Skip to content

Commit

Permalink
smoothen progress bar (#4038)
Browse files Browse the repository at this point in the history
Co-authored-by: KristofferC <[email protected]>
  • Loading branch information
KristofferC and KristofferC authored Oct 8, 2024
1 parent 2f5cdae commit e099a62
Showing 1 changed file with 12 additions and 4 deletions.
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

0 comments on commit e099a62

Please sign in to comment.