From 578f336527ab7bb2fcdb1e754f3490560498fddc Mon Sep 17 00:00:00 2001 From: Marc Ittel Date: Tue, 9 Nov 2021 14:13:46 +0100 Subject: [PATCH 1/2] keepall for Progress --- src/ProgressMeter.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ProgressMeter.jl b/src/ProgressMeter.jl index 641bfb8..35ec63f 100644 --- a/src/ProgressMeter.jl +++ b/src/ProgressMeter.jl @@ -257,7 +257,7 @@ end # update progress display function updateProgress!(p::Progress; showvalues = (), truncate_lines = false, valuecolor = :blue, offset::Integer = p.offset, keep = (offset == 0), desc::Union{Nothing,AbstractString} = nothing, - ignore_predictor = false) + ignore_predictor = false, keepall=false) (!RUNNING_IJULIA_KERNEL[] & !p.enabled) && return if p.counter == 2 # ignore the first loop given usually uncharacteristically slow p.tsecond = time() @@ -321,7 +321,11 @@ function updateProgress!(p::Progress; showvalues = (), truncate_lines = false, v move_cursor_up_while_clearing_lines(p.output, p.numprintedvalues) printover(p.output, msg, p.color) printvalues!(p, showvalues; color = valuecolor, truncate = truncate_lines) - !CLEAR_IJULIA[] && print(p.output, "\r\u1b[A" ^ (p.offset + p.numprintedvalues)) + if keepall + println(p.output) + else + !CLEAR_IJULIA[] && print(p.output, "\r\u1b[A" ^ (p.offset + p.numprintedvalues)) + end flush(p.output) # Compensate for any overhead of printing. This can be # especially important if you're running over a slow network From d529787f5decbce37a70da9539218f250a1d323c Mon Sep 17 00:00:00 2001 From: Marc Ittel Date: Tue, 9 Nov 2021 15:18:44 +0100 Subject: [PATCH 2/2] add notover in printover --- src/ProgressMeter.jl | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/ProgressMeter.jl b/src/ProgressMeter.jl index 3dfbcc8..bd4b416 100644 --- a/src/ProgressMeter.jl +++ b/src/ProgressMeter.jl @@ -278,11 +278,13 @@ function updateProgress!(p::Progress; showvalues = (), truncate_lines = false, v sec_per_iter = elapsed_time / (p.counter - p.start) msg = @sprintf "%s (%s)" msg speedstring(sec_per_iter) end - !CLEAR_IJULIA[] && print(p.output, "\n" ^ (p.offset + p.numprintedvalues)) - move_cursor_up_while_clearing_lines(p.output, p.numprintedvalues) - printover(p.output, msg, p.color) - printvalues!(p, showvalues; color = valuecolor, truncate = truncate_lines) - if keep + if !keepall + !CLEAR_IJULIA[] && print(p.output, "\n" ^ (p.offset + p.numprintedvalues)) + move_cursor_up_while_clearing_lines(p.output, p.numprintedvalues) + end + printover(p.output, msg, p.color; notover=keepall) + printvalues!(p, showvalues; color = valuecolor, truncate = truncate_lines, notover=keepall) + if keep || keepall println(p.output) else print(p.output, "\r\u1b[A" ^ (p.offset + p.numprintedvalues)) @@ -313,14 +315,17 @@ function updateProgress!(p::Progress; showvalues = (), truncate_lines = false, v sec_per_iter = elapsed_time / (p.counter - p.start) msg = @sprintf "%s (%s)" msg speedstring(sec_per_iter) end - !CLEAR_IJULIA[] && print(p.output, "\n" ^ (p.offset + p.numprintedvalues)) - move_cursor_up_while_clearing_lines(p.output, p.numprintedvalues) - printover(p.output, msg, p.color) - printvalues!(p, showvalues; color = valuecolor, truncate = truncate_lines) + + if !keepall + !CLEAR_IJULIA[] && print(p.output, "\n" ^ (p.offset + p.numprintedvalues)) + move_cursor_up_while_clearing_lines(p.output, p.numprintedvalues) + end + printover(p.output, msg, p.color; notover=keepall) + printvalues!(p, showvalues; color = valuecolor, truncate = truncate_lines, notover=keepall) if keepall println(p.output) else - !CLEAR_IJULIA[] && print(p.output, "\r\u1b[A" ^ (p.offset + p.numprintedvalues)) + print(p.output, "\r\u1b[A" ^ (p.offset + p.numprintedvalues)) end flush(p.output) # Compensate for any overhead of printing. This can be @@ -586,7 +591,7 @@ function finish!(p::ProgressUnknown; options...) end # Internal method to print additional values below progress bar -function printvalues!(p::AbstractProgress, showvalues; color = :normal, truncate = false) +function printvalues!(p::AbstractProgress, showvalues; color = :normal, truncate = false, notover = false) length(showvalues) == 0 && return maxwidth = maximum(Int[length(string(name)) for (name, _) in showvalues]) @@ -600,10 +605,10 @@ function printvalues!(p::AbstractProgress, showvalues; color = :normal, truncate msg_lines = ceil(Int, (length(msg)-1) / max_len) if truncate && msg_lines >= 2 # For multibyte characters, need to index with nextind. - printover(p.output, msg[1:nextind(msg, 1, max_len-1)] * "…", color) + printover(p.output, msg[1:nextind(msg, 1, max_len-1)] * "…", color; notover=notover) p.numprintedvalues += 1 else - printover(p.output, msg, color) + printover(p.output, msg, color; notover=notover) p.numprintedvalues += msg_lines end end @@ -626,12 +631,12 @@ function move_cursor_up_while_clearing_lines(io, numlinesup) end end -function printover(io::IO, s::AbstractString, color::Symbol = :color_normal) - print(io, "\r") +function printover(io::IO, s::AbstractString, color::Symbol = :normal; notover = false) + !notover && print(io, "\r") printstyled(io, s; color=color) if isdefined(Main, :IJulia) Main.IJulia.stdio_bytes[] = 0 # issue #76: circumvent IJulia I/O throttling - elseif isdefined(Main, :ESS) || isdefined(Main, :Atom) + elseif isdefined(Main, :ESS) || isdefined(Main, :Atom) || notover else print(io, "\u1b[K") # clear the rest of the line end