Skip to content
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

smoothen progress bar #4038

Merged
merged 1 commit into from
Oct 8, 2024
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
16 changes: 12 additions & 4 deletions src/MiniProgressBars.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ function show_progress(io::IO, p::MiniProgressBar; termwidth=nothing, carriagere
end
termwidth = @something termwidth displaysize(io)[2]
max_progress_width = max(0, min(termwidth - textwidth(p.header) - textwidth(progress_text) - 10 , p.width))
n_filled = ceil(Int, max_progress_width * perc / 100)
n_left = max_progress_width - n_filled
n_filled = floor(Int, max_progress_width * perc / 100)
partial_filled = (max_progress_width * perc / 100) - n_filled
n_left = max_progress_width - n_filled - 1
headers = split(p.header)
to_print = sprint(; context=io) do io
print(io, " "^p.indent)
Expand All @@ -88,8 +89,15 @@ function show_progress(io::IO, p::MiniProgressBar; termwidth=nothing, carriagere
print(io, p.status)
else
printstyled(io, "━"^n_filled; color=p.color)
printstyled(io, perc >= 95 ? "━" : "╸"; color=p.color)
printstyled(io, "━"^n_left, " "; color=:light_black)
if n_left > 0
if partial_filled > 0.5
printstyled(io, "╸"; color=p.color) # More filled, use ╸
else
printstyled(io, "╺"; color=:light_black) # Less filled, use ╺
end
printstyled(io, "━"^n_left; color=:light_black)
end
printstyled(io, " "; color=:light_black)
print(io, progress_text)
end
carriagereturn && print(io, "\r")
Expand Down
Loading