Skip to content

Commit

Permalink
updateProgress!(): add force=t/f kwarg (#315)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexey Stukalov <[email protected]>
  • Loading branch information
alyst and Alexey Stukalov authored Jul 13, 2024
1 parent 66ad2be commit cf6a596
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/ProgressMeter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ 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, color = p.color, max_steps = p.n)
ignore_predictor = false, force::Bool = false,
color = p.color, max_steps = p.n)
!p.enabled && return
if p.counter == 2 # ignore the first loop given usually uncharacteristically slow
p.tsecond = time()
Expand Down Expand Up @@ -253,12 +254,12 @@ function updateProgress!(p::Progress; showvalues = (),
end
return nothing
end
if ignore_predictor || predicted_updates_per_dt_have_passed(p)
if force || ignore_predictor || predicted_updates_per_dt_have_passed(p)
t = time()
if p.counter > 2
p.check_iterations = calc_check_iterations(p, t)
end
if t > p.tlast+p.dt
if force || (t > p.tlast+p.dt)
barlen = p.barlen isa Nothing ? tty_width(p.desc, p.output, p.showspeed) : p.barlen
percentage_complete = 100.0 * p.counter / p.n
percentage_rounded = min(99, round(Int, percentage_complete)) # don't round up to 100% if not finished (#300)
Expand Down Expand Up @@ -297,7 +298,8 @@ end
function updateProgress!(p::ProgressThresh; showvalues = (),
truncate_lines = false, valuecolor = :blue,
offset::Integer = p.offset, keep = (offset == 0),
desc = p.desc, ignore_predictor = false,
desc = p.desc,
ignore_predictor = false, force::Bool = false,
color = p.color, thresh = p.thresh)
!p.enabled && return
p.offset = offset
Expand Down Expand Up @@ -330,12 +332,12 @@ function updateProgress!(p::ProgressThresh; showvalues = (),
return
end

if ignore_predictor || predicted_updates_per_dt_have_passed(p)
if force || ignore_predictor || predicted_updates_per_dt_have_passed(p)
t = time()
if p.counter > 2
p.check_iterations = calc_check_iterations(p, t)
end
if t > p.tlast+p.dt && !p.triggered
if force || (t > p.tlast+p.dt && !p.triggered)
msg = @sprintf "%s (thresh = %g, value = %g)" p.desc p.thresh p.val
if p.showspeed
elapsed_time = t - p.tinit
Expand Down Expand Up @@ -368,7 +370,8 @@ spinner_char(p::ProgressUnknown, spinner::AbstractString) =
p.done ? spinner_done : spinner[nextind(spinner, 1, p.spincounter % length(spinner))]

function updateProgress!(p::ProgressUnknown; showvalues = (), truncate_lines = false,
valuecolor = :blue, desc = p.desc, ignore_predictor = false,
valuecolor = :blue, desc = p.desc,
ignore_predictor = false, force::Bool = false,
spinner::Union{AbstractChar,AbstractString,AbstractVector{<:AbstractChar}} = spinner_chars,
offset::Integer = p.offset, keep = (offset == 0),
color = p.color)
Expand Down Expand Up @@ -404,12 +407,12 @@ function updateProgress!(p::ProgressUnknown; showvalues = (), truncate_lines = f
end
return
end
if ignore_predictor || predicted_updates_per_dt_have_passed(p)
if force || ignore_predictor || predicted_updates_per_dt_have_passed(p)
t = time()
if p.counter > 2
p.check_iterations = calc_check_iterations(p, t)
end
if t > p.tlast+p.dt
if force || (t > p.tlast+p.dt)
dur = durationstring(t-p.tinit)
if p.spinner
msg = @sprintf "%c %s Time: %s" spinner_char(p, spinner) p.desc dur
Expand Down

0 comments on commit cf6a596

Please sign in to comment.