Skip to content

Simplify progress bar display logic #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,12 @@ progress() {
local bar_left
bar_left=$(printf "%${left}s")

# If no leftover space remains, we have presumably reached 100%.
if [ "$left" -eq 0 ]; then
# Clear the existing progress line
printf "\r\033[K"
# FIXME: remove this hack to print the final 100% bar with a newline
printf "Progress: [########################################] 100%%\n"
else
# Update the bar in place (no extra newline)
printf "\rProgress: [${bar_done// /#}${bar_left// /-}] ${percentage}%%"
# Print the progress bar in a single line, updating it dynamically.
printf "\rProgress: [%s%s] %d%%" "${bar_done// /#}" "${bar_left// /-}" "$percentage"

# When reaching 100%, automatically print a newline to finalize the output.
if [ "$percentage" -eq 100 ]; then
printf "\n"
fi
}

Expand Down
Loading