Skip to content

Commit

Permalink
Update to use clear lines
Browse files Browse the repository at this point in the history
  • Loading branch information
RobLoach committed Oct 3, 2024
1 parent 4edc3e3 commit 669fac2
Showing 1 changed file with 45 additions and 30 deletions.
75 changes: 45 additions & 30 deletions plugins/progress/progress.plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ function progress()
local message=$2;

if [ -z $value ]; then
printf "Usage: progress <value> [message]\n\n"
printf "Options:\n"
printf " value The value for the progress bar. Use 0 to reset.\n"
printf " message The optional message to display next to the progress bar.\n"
printf 'Usage: progress <value> [message]\n\n'
printf 'Options:\n'
printf ' value The value for the progress bar. Use 0 to reset.\n'
printf ' message The optional message to display next to the progress bar.\n'
return 2
fi

Expand All @@ -55,33 +55,48 @@ function progress()
return 0
fi

# Clear the message whitespace
local size=$((40-${#message}))
local whitespace=""
for ((i=0; i<size; i++)); do
whitespace="$whitespace "
done
# Get a clear line escape sequence
local clear_line
if _omb_util_command_exists 'tput'; then
clear_line=$(tput el)
if [ -z $clear_line ]; then
clear_line=$(tput el1)
if [ -z $clear_line ]; then
clear_line=$(tput ce)
fi
fi
fi
if [ -z $clear_line ]; then
clear_line="\e[K"
fi

if [ $_omb_plugin_progress_value -le 0 -a $value -ge 0 ] ; then echo -ne "[--------------------------] (0%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 5 -a $value -ge 5 ] ; then echo -ne "[#-------------------------] (5%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 10 -a $value -ge 10 ]; then echo -ne "[##------------------------] (10%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 15 -a $value -ge 15 ]; then echo -ne "[###-----------------------] (15%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 20 -a $value -ge 20 ]; then echo -ne "[####----------------------] (20%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 25 -a $value -ge 25 ]; then echo -ne "[#####---------------------] (25%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 30 -a $value -ge 30 ]; then echo -ne "[######--------------------] (30%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 35 -a $value -ge 35 ]; then echo -ne "[#######-------------------] (35%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 40 -a $value -ge 40 ]; then echo -ne "[########------------------] (40%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 45 -a $value -ge 45 ]; then echo -ne "[#########-----------------] (45%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 50 -a $value -ge 50 ]; then echo -ne "[##########----------------] (50%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 55 -a $value -ge 55 ]; then echo -ne "[###########---------------] (55%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 60 -a $value -ge 60 ]; then echo -ne "[############--------------] (60%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 65 -a $value -ge 65 ]; then echo -ne "[#############-------------] (65%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 70 -a $value -ge 70 ]; then echo -ne "[###############-----------] (70%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 75 -a $value -ge 75 ]; then echo -ne "[#################---------] (75%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 80 -a $value -ge 80 ]; then echo -ne "[####################------] (80%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 85 -a $value -ge 85 ]; then echo -ne "[#######################---] (90%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 90 -a $value -ge 90 ]; then echo -ne "[##########################] (100%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 100 -a $value -ge 100 ];then echo -ne 'Done! \n' ; delay; fi;
if [ $_omb_plugin_progress_value -le 0 -a $value -ge 0 ] ; then printf "%s[--------------------] (0%%) %s\r" "$clear_line" "$message" ; delay; fi;
if [ $_omb_plugin_progress_value -le 5 -a $value -ge 5 ] ; then printf "%s[#-------------------] (5%%) %s\r" "$clear_line" "$message" ; delay; fi;
if [ $_omb_plugin_progress_value -le 10 -a $value -ge 10 ]; then printf "%s[##------------------] (10%%) %s\r" "$clear_line" "$message" ; delay; fi;
if [ $_omb_plugin_progress_value -le 15 -a $value -ge 15 ]; then printf "%s[###-----------------] (15%%) %s\r" "$clear_line" "$message" ; delay; fi;
if [ $_omb_plugin_progress_value -le 20 -a $value -ge 20 ]; then printf "%s[####----------------] (20%%) %s\r" "$clear_line" "$message" ; delay; fi;
if [ $_omb_plugin_progress_value -le 25 -a $value -ge 25 ]; then printf "%s[#####---------------] (25%%) %s\r" "$clear_line" "$message" ; delay; fi;
if [ $_omb_plugin_progress_value -le 30 -a $value -ge 30 ]; then printf "%s[######--------------] (30%%) %s\r" "$clear_line" "$message" ; delay; fi;
if [ $_omb_plugin_progress_value -le 35 -a $value -ge 35 ]; then printf "%s[#######-------------] (35%%) %s\r" "$clear_line" "$message" ; delay; fi;
if [ $_omb_plugin_progress_value -le 40 -a $value -ge 40 ]; then printf "%s[########------------] (40%%) %s\r" "$clear_line" "$message" ; delay; fi;
if [ $_omb_plugin_progress_value -le 45 -a $value -ge 45 ]; then printf "%s[#########-----------] (45%%) %s\r" "$clear_line" "$message" ; delay; fi;
if [ $_omb_plugin_progress_value -le 50 -a $value -ge 50 ]; then printf "%s[##########----------] (50%%) %s\r" "$clear_line" "$message" ; delay; fi;
if [ $_omb_plugin_progress_value -le 55 -a $value -ge 55 ]; then printf "%s[###########---------] (55%%) %s\r" "$clear_line" "$message" ; delay; fi;
if [ $_omb_plugin_progress_value -le 60 -a $value -ge 60 ]; then printf "%s[############--------] (60%%) %s\r" "$clear_line" "$message" ; delay; fi;
if [ $_omb_plugin_progress_value -le 65 -a $value -ge 65 ]; then printf "%s[#############-------] (65%%) %s\r" "$clear_line" "$message" ; delay; fi;
if [ $_omb_plugin_progress_value -le 70 -a $value -ge 70 ]; then printf "%s[##############------] (70%%) %s\r" "$clear_line" "$message" ; delay; fi;
if [ $_omb_plugin_progress_value -le 75 -a $value -ge 75 ]; then printf "%s[###############-----] (75%%) %s\r" "$clear_line" "$message" ; delay; fi;
if [ $_omb_plugin_progress_value -le 80 -a $value -ge 80 ]; then printf "%s[################----] (80%%) %s\r" "$clear_line" "$message" ; delay; fi;
if [ $_omb_plugin_progress_value -le 85 -a $value -ge 85 ]; then printf "%s[#################---] (85%%) %s\r" "$clear_line" "$message" ; delay; fi;
if [ $_omb_plugin_progress_value -le 90 -a $value -ge 90 ]; then printf "%s[##################--] (90%%) %s\r" "$clear_line" "$message" ; delay; fi;
if [ $_omb_plugin_progress_value -le 95 -a $value -ge 95 ]; then printf "%s[###################-] (95%%) %s\r" "$clear_line" "$message" ; delay; fi;
if [ $_omb_plugin_progress_value -le 100 -a $value -ge 100 ]; then
# Display the finished progress bar, and then clear with a new line.
printf "%s[####################] (100%%) %s\r" "$clear_line" "$message"
delay
printf "%s\n" "$clear_line"
value=0
fi;

_omb_plugin_progress_value=$value;
}

0 comments on commit 669fac2

Please sign in to comment.