diff --git a/progress_bar.nu b/progress_bar.nu index 88a3828..245b4d6 100644 --- a/progress_bar.nu +++ b/progress_bar.nu @@ -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) \ No newline at end of file diff --git a/progress_bar_no_back.nu b/progress_bar_no_back.nu new file mode 100644 index 0000000..48c52bd --- /dev/null +++ b/progress_bar_no_back.nu @@ -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) + diff --git a/stdlib_candidate/print.nu b/stdlib_candidate/print.nu index 833175f..5da3340 100644 --- a/stdlib_candidate/print.nu +++ b/stdlib_candidate/print.nu @@ -23,4 +23,20 @@ def print [ # 1--2--3--four # > print 1 2 3 "four" -# 123four \ No newline at end of file +# 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 + } +}