From 7241673d1858731e2f4a0c62dad6c0f64fded110 Mon Sep 17 00:00:00 2001 From: Christian Guinard <28689358+christiangnrd@users.noreply.github.com> Date: Sun, 13 Oct 2024 16:21:45 -0300 Subject: [PATCH] Port progress bar improvements from Pkg (#56125) Includes changes from https://github.com/JuliaLang/Pkg.jl/pull/4038 and https://github.com/JuliaLang/Pkg.jl/pull/4044. Co-authored-by: Kristoffer Carlsson --- base/precompilation.jl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/base/precompilation.jl b/base/precompilation.jl index ea98b0c415ab4..7a821222c52d1 100644 --- a/base/precompilation.jl +++ b/base/precompilation.jl @@ -297,7 +297,8 @@ 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_filled = floor(Int, max_progress_width * perc / 100) + partial_filled = (max_progress_width * perc / 100) - n_filled n_left = max_progress_width - n_filled headers = split(p.header, ' ') to_print = sprint(; context=io) do io @@ -306,8 +307,15 @@ function show_progress(io::IO, p::MiniProgressBar; termwidth=nothing, carriagere printstyled(io, join(headers[2:end], ' ')) print(io, " ") 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-1); color=:light_black) + end + printstyled(io, " "; color=:light_black) print(io, progress_text) carriagereturn && print(io, "\r") end