mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 06:37:46 +00:00
Merge pull request #6 from fdncred/main
added progress bar prototypes and update print
This commit is contained in:
commit
05b7234d39
3 changed files with 70 additions and 11 deletions
|
@ -1,22 +1,48 @@
|
|||
# progress bar attempt - not 100% yet
|
||||
# progress bar attempt
|
||||
# https://askubuntu.com/questions/747143/create-a-progress-bar-in-bash
|
||||
# https://www.shellscript.sh/tips/progressbar/
|
||||
|
||||
# There is a strange artifact drawing the first two full blocks
|
||||
# You can see this artifact better in progress_bar_no_back.nu
|
||||
# I'm not sure what's going on nor how to fix it.
|
||||
|
||||
let pb_len = 25
|
||||
let bg_fill = "▒" # Fill up to $pb_len
|
||||
let blocks = ["▏" "▎" "▍" "▌" "▋" "▊" "▉" "█"]
|
||||
|
||||
let fill = "▒" # Fill up to $Len
|
||||
let arr = [ "▉" "▎" "▌" "▊" ] # UTF-8 left blocks: 7/8, 1/4, 1/2, 3/4
|
||||
let pb_len = 10
|
||||
# "█" #8/8
|
||||
# "▉" #7/8
|
||||
# "▊" #3/4
|
||||
# "▋" #5/8
|
||||
# "▌" #1/2
|
||||
# "▍" #3/8
|
||||
# "▎" #1/4
|
||||
# "▏" #1/8
|
||||
|
||||
# Turn off the cursor
|
||||
echo $(ansi cursor_off)
|
||||
|
||||
#Move cursor all the way to the left
|
||||
# Move cursor all the way to the left
|
||||
echo $(ansi -e '1000D') | autoview
|
||||
echo $fill | str lpad -c $fill -l $pb_len
|
||||
echo 1..$pb_len | each {
|
||||
sleep 50ms
|
||||
echo $arr.0 | str lpad -c $arr.0 -l $it | autoview
|
||||
# Draw the background for the progress bar
|
||||
echo $bg_fill | str lpad -c $bg_fill -l $pb_len
|
||||
|
||||
echo 1..<$pb_len | each {
|
||||
# This is kind of a hack because it's not incrementally drawing a new box
|
||||
# It's drawing the entire row every time with a different padding amount
|
||||
# echo $blocks.7 | str lpad -c $blocks.7 -l $it | autoview
|
||||
|
||||
let cur_progress = $it
|
||||
echo 0..7 | each {
|
||||
let cur_idx = $(= $it mod 8)
|
||||
let cur_block = $(echo $blocks | nth $cur_idx)
|
||||
echo $cur_block | str lpad -c $blocks.7 -l $cur_progress | autoview
|
||||
echo $(ansi -e '1000D') | autoview
|
||||
sleep 50ms
|
||||
}
|
||||
echo $(ansi -e '1000D') | autoview
|
||||
}
|
||||
# Fill in the last background block
|
||||
echo $blocks.7 | str lpad -c $blocks.7 -l $pb_len | autoview
|
||||
echo $(char newline)
|
||||
echo "Done"
|
||||
echo $(ansi cursor_on)
|
17
progress_bar_no_back.nu
Normal file
17
progress_bar_no_back.nu
Normal file
|
@ -0,0 +1,17 @@
|
|||
let blocks = ["▏" "▎" "▍" "▌" "▋" "▊" "▉" "█"]
|
||||
let pb_size = 25
|
||||
echo $(ansi cursor_off)
|
||||
echo 1..<$pb_size | each {
|
||||
let cur_size = $it
|
||||
echo 0..7 | each {
|
||||
let idx = $(= $it mod 8)
|
||||
let cur_block = $(echo $blocks | nth $idx)
|
||||
echo $cur_block | str lpad -c $blocks.7 -l $cur_size | autoview
|
||||
echo $(ansi -e '1000D') | autoview
|
||||
sleep 50ms
|
||||
}
|
||||
}
|
||||
echo $(char newline)
|
||||
echo 'Done'
|
||||
echo $(ansi cursor_on)
|
||||
|
|
@ -24,3 +24,19 @@ def print [
|
|||
|
||||
# > print 1 2 3 "four"
|
||||
# 123four
|
||||
|
||||
# An alternate print command that concatenates arguments together with an optional separator.
|
||||
# This one uses str collect instead of build-string.
|
||||
# By default there will be no newline
|
||||
def print2 [
|
||||
--separator(-s):any # Optional separator (not yet flagged as optional?)
|
||||
...rest # All of the parameters
|
||||
] {
|
||||
let is_empty = $(= $separator | empty?)
|
||||
let num_of_rest = $(echo $rest | count)
|
||||
if $is_empty {
|
||||
echo $rest | str from | str collect
|
||||
} {
|
||||
echo $rest | str from | str collect $separator
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue