Skip to content

Commit

Permalink
perf(plugins/progress): cache the result of "clear_line"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Dec 18, 2024
1 parent 7be64e3 commit 13c7b69
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions plugins/progress/progress.plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
# Global variable to store progress value
_omb_plugin_progress_value=0

_omb_plugin_progress_clear_line=

#
# Description : delay executing script
#
Expand Down Expand Up @@ -56,10 +58,13 @@ function progress {
fi

# Get a clear line escape sequence
local clear_line
clear_line=$(tput el 2>/dev/null || tput ce 2>/dev/null)
local clear_line=$_omb_plugin_progress_clear_line
if [[ ! $clear_line ]]; then
clear_line=$'\e[K'
clear_line=$(tput el 2>/dev/null || tput ce 2>/dev/null)
if [[ ! $clear_line ]]; then
clear_line=$'\e[K'
fi
_omb_plugin_progress_clear_line=$clear_line
fi

if ((_omb_plugin_progress_value <= 0 && value >= 0)); then printf "%s[............................] (0%%) %s\r" "$clear_line" "$message"; delay; fi
Expand Down

0 comments on commit 13c7b69

Please sign in to comment.