Skip to content

Commit e427460

Browse files
authored
Merge pull request #271 from EricccTaiwan/fix-progess-bar
Simplify progress bar display logic
2 parents 051742b + 4a2ff9f commit e427460

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

scripts/common.sh

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,12 @@ progress() {
5454
local bar_left
5555
bar_left=$(printf "%${left}s")
5656

57-
# If no leftover space remains, we have presumably reached 100%.
58-
if [ "$left" -eq 0 ]; then
59-
# Clear the existing progress line
60-
printf "\r\033[K"
61-
# FIXME: remove this hack to print the final 100% bar with a newline
62-
printf "Progress: [########################################] 100%%\n"
63-
else
64-
# Update the bar in place (no extra newline)
65-
printf "\rProgress: [${bar_done// /#}${bar_left// /-}] ${percentage}%%"
57+
# Print the progress bar in a single line, updating it dynamically.
58+
printf "\rProgress: [%s%s] %d%%" "${bar_done// /#}" "${bar_left// /-}" "$percentage"
59+
60+
# When reaching 100%, automatically print a newline to finalize the output.
61+
if [ "$percentage" -eq 100 ]; then
62+
printf "\n"
6663
fi
6764
}
6865

0 commit comments

Comments
 (0)