From ead2d03a91fa9bb2c24d2ece16f3bede22c6d556 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Thu, 3 Oct 2024 00:27:28 -0400 Subject: [PATCH 1/7] plugins: Improve progress plugin --- plugins/progress/README.md | 4 +- plugins/progress/progress.plugin.sh | 79 +++++++++++++++++++---------- 2 files changed, 55 insertions(+), 28 deletions(-) diff --git a/plugins/progress/README.md b/plugins/progress/README.md index 5d4e226ef..5491c0c8c 100644 --- a/plugins/progress/README.md +++ b/plugins/progress/README.md @@ -22,8 +22,8 @@ Bash. The function handles printing of the progress bar. 2. **Invoke `progress` Function:** - Within a shell function, call the `progress` function whenever you want to display the progress bar. - Pass two parameters to the `progress` function: - - `PARAM_PROGRESS`: The progress percentage (0-100) of the task. - - `PARAM_STATUS`: Optional. A status message to display alongside the progress bar. + - `value`: The progress percentage (0-100) of the task. Passing 0 will reset the progress bar status. + - `message`: Optional. A status message to display alongside the progress bar. ```bash # Example usage: diff --git a/plugins/progress/progress.plugin.sh b/plugins/progress/progress.plugin.sh index b00cb536d..a141016ad 100644 --- a/plugins/progress/progress.plugin.sh +++ b/plugins/progress/progress.plugin.sh @@ -17,6 +17,8 @@ ################################################################################ +# Global variable to store progress value +_omb_plugin_progress_value=0 # # Description : delay executing script @@ -29,32 +31,57 @@ function delay() # # Description : print out executing progress # -CURRENT_PROGRESS=0 function progress() { - PARAM_PROGRESS=$1; - PARAM_STATUS=$2; - - if [ $CURRENT_PROGRESS -le 0 -a $PARAM_PROGRESS -ge 0 ] ; then printf "[..........................] (0%) %s \r" "$PARAM_PHASE" ; delay; fi; - if [ $CURRENT_PROGRESS -le 5 -a $PARAM_PROGRESS -ge 5 ] ; then printf "[#.........................] (5%) %s \r" "$PARAM_PHASE" ; delay; fi; - if [ $CURRENT_PROGRESS -le 10 -a $PARAM_PROGRESS -ge 10 ]; then printf "[##........................] (10%) %s \r" "$PARAM_PHASE" ; delay; fi; - if [ $CURRENT_PROGRESS -le 15 -a $PARAM_PROGRESS -ge 15 ]; then printf "[###.......................] (15%) %s \r" "$PARAM_PHASE" ; delay; fi; - if [ $CURRENT_PROGRESS -le 20 -a $PARAM_PROGRESS -ge 20 ]; then printf "[####......................] (20%) %s \r" "$PARAM_PHASE" ; delay; fi; - if [ $CURRENT_PROGRESS -le 25 -a $PARAM_PROGRESS -ge 25 ]; then printf "[#####.....................] (25%) %s \r" "$PARAM_PHASE" ; delay; fi; - if [ $CURRENT_PROGRESS -le 30 -a $PARAM_PROGRESS -ge 30 ]; then printf "[######....................] (30%) %s \r" "$PARAM_PHASE" ; delay; fi; - if [ $CURRENT_PROGRESS -le 35 -a $PARAM_PROGRESS -ge 35 ]; then printf "[#######...................] (35%) %s \r" "$PARAM_PHASE" ; delay; fi; - if [ $CURRENT_PROGRESS -le 40 -a $PARAM_PROGRESS -ge 40 ]; then printf "[########..................] (40%) %s \r" "$PARAM_PHASE" ; delay; fi; - if [ $CURRENT_PROGRESS -le 45 -a $PARAM_PROGRESS -ge 45 ]; then printf "[#########.................] (45%) %s \r" "$PARAM_PHASE" ; delay; fi; - if [ $CURRENT_PROGRESS -le 50 -a $PARAM_PROGRESS -ge 50 ]; then printf "[##########................] (50%) %s \r" "$PARAM_PHASE" ; delay; fi; - if [ $CURRENT_PROGRESS -le 55 -a $PARAM_PROGRESS -ge 55 ]; then printf "[###########...............] (55%) %s \r" "$PARAM_PHASE" ; delay; fi; - if [ $CURRENT_PROGRESS -le 60 -a $PARAM_PROGRESS -ge 60 ]; then printf "[############..............] (60%) %s \r" "$PARAM_PHASE" ; delay; fi; - if [ $CURRENT_PROGRESS -le 65 -a $PARAM_PROGRESS -ge 65 ]; then printf "[#############.............] (65%) %s \r" "$PARAM_PHASE" ; delay; fi; - if [ $CURRENT_PROGRESS -le 70 -a $PARAM_PROGRESS -ge 70 ]; then printf "[###############...........] (70%) %s \r" "$PARAM_PHASE" ; delay; fi; - if [ $CURRENT_PROGRESS -le 75 -a $PARAM_PROGRESS -ge 75 ]; then printf "[#################.........] (75%) %s \r" "$PARAM_PHASE" ; delay; fi; - if [ $CURRENT_PROGRESS -le 80 -a $PARAM_PROGRESS -ge 80 ]; then printf "[####################......] (80%) %s \r" "$PARAM_PHASE" ; delay; fi; - if [ $CURRENT_PROGRESS -le 85 -a $PARAM_PROGRESS -ge 85 ]; then printf "[#######################...] (90%) %s \r" "$PARAM_PHASE" ; delay; fi; - if [ $CURRENT_PROGRESS -le 90 -a $PARAM_PROGRESS -ge 90 ]; then printf "[##########################] (100%) %s \r" "$PARAM_PHASE"; delay; fi; - if [ $CURRENT_PROGRESS -le 100 -a $PARAM_PROGRESS -ge 100 ];then printf 'Done! \n' ; delay; fi; - - CURRENT_PROGRESS=$PARAM_PROGRESS; + local value=$1; + local message=$2; + + if [ -z $value ]; then + printf "Usage: progress [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 0 + fi + + if [ $value -lt 0 ]; then + _omb_log_error "invalid value: value' (expect: 0-100)" >&2 + return 2 + fi + + # Reset the progress value + if [ $value -eq 0 ]; then + _omb_plugin_progress_value=0; + return 0 + fi + + # Clear the message whitespace + local size=40-${#message} + local whitespace="" + for ((i=0; i Date: Thu, 3 Oct 2024 01:57:39 -0400 Subject: [PATCH 2/7] Update plugins/progress/progress.plugin.sh Co-authored-by: Koichi Murase --- plugins/progress/progress.plugin.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/progress/progress.plugin.sh b/plugins/progress/progress.plugin.sh index a141016ad..04a20b89a 100644 --- a/plugins/progress/progress.plugin.sh +++ b/plugins/progress/progress.plugin.sh @@ -56,7 +56,7 @@ function progress() fi # Clear the message whitespace - local size=40-${#message} + local size=$((40-${#message})) local whitespace="" for ((i=0; i Date: Thu, 3 Oct 2024 02:00:24 -0400 Subject: [PATCH 3/7] Update plugins/progress/progress.plugin.sh Co-authored-by: Koichi Murase --- plugins/progress/progress.plugin.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/progress/progress.plugin.sh b/plugins/progress/progress.plugin.sh index 04a20b89a..58079a1dc 100644 --- a/plugins/progress/progress.plugin.sh +++ b/plugins/progress/progress.plugin.sh @@ -41,7 +41,7 @@ function progress() 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 0 + return 2 fi if [ $value -lt 0 ]; then From 669fac286b129e3285c07b7a9af5837fc8a371fa Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Thu, 3 Oct 2024 12:34:56 -0400 Subject: [PATCH 4/7] Update to use clear lines --- plugins/progress/progress.plugin.sh | 75 +++++++++++++++++------------ 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/plugins/progress/progress.plugin.sh b/plugins/progress/progress.plugin.sh index 58079a1dc..d1506b5ef 100644 --- a/plugins/progress/progress.plugin.sh +++ b/plugins/progress/progress.plugin.sh @@ -37,10 +37,10 @@ function progress() local message=$2; if [ -z $value ]; then - printf "Usage: progress [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 [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 @@ -55,33 +55,48 @@ function progress() return 0 fi - # Clear the message whitespace - local size=$((40-${#message})) - local whitespace="" - for ((i=0; i Date: Thu, 3 Oct 2024 14:53:27 -0400 Subject: [PATCH 5/7] Use . instead of - --- plugins/progress/progress.plugin.sh | 41 +++++++++++++++-------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/plugins/progress/progress.plugin.sh b/plugins/progress/progress.plugin.sh index d1506b5ef..e10d80a2a 100644 --- a/plugins/progress/progress.plugin.sh +++ b/plugins/progress/progress.plugin.sh @@ -70,26 +70,27 @@ function progress() clear_line="\e[K" 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 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" From fd000a00545eb592539273ceb81c5b6a43759954 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Fri, 4 Oct 2024 02:15:24 -0400 Subject: [PATCH 6/7] Update plugins/progress/progress.plugin.sh Co-authored-by: Koichi Murase --- plugins/progress/progress.plugin.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/progress/progress.plugin.sh b/plugins/progress/progress.plugin.sh index e10d80a2a..885350c5f 100644 --- a/plugins/progress/progress.plugin.sh +++ b/plugins/progress/progress.plugin.sh @@ -67,7 +67,7 @@ function progress() fi fi if [ -z $clear_line ]; then - clear_line="\e[K" + clear_line=$'\e[K' fi if [ $_omb_plugin_progress_value -le 0 -a $value -ge 0 ] ; then printf "%s[....................] (0%%) %s\r" "$clear_line" "$message" ; delay; fi; From 5a4d0eb1dbadbc154532a12bbe7292bcb83015ea Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Fri, 4 Oct 2024 02:15:33 -0400 Subject: [PATCH 7/7] Update plugins/progress/progress.plugin.sh Co-authored-by: Koichi Murase --- plugins/progress/progress.plugin.sh | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/plugins/progress/progress.plugin.sh b/plugins/progress/progress.plugin.sh index 885350c5f..4c7eaadae 100644 --- a/plugins/progress/progress.plugin.sh +++ b/plugins/progress/progress.plugin.sh @@ -57,15 +57,7 @@ function progress() # 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 + clear_line=$(tput el 2>/dev/null || tput ce 2>/dev/null) if [ -z $clear_line ]; then clear_line=$'\e[K' fi