From f14f6243515ccf6bece423234221da601d0c66c8 Mon Sep 17 00:00:00 2001 From: Sebastian Pfitzner Date: Wed, 16 May 2018 19:33:58 +0200 Subject: [PATCH] actually fix progress this time --- src/progress.jl | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/progress.jl b/src/progress.jl index 2948ad3..33d75a8 100644 --- a/src/progress.jl +++ b/src/progress.jl @@ -88,13 +88,38 @@ _progress(ex) = _progress("", 0.005, ex) _progress(name::AbstractString, ex) = _progress(name, 0.005, ex) _progress(thresh::Real, ex) = _progress("", thresh, ex) - function _progress(name, thresh, ex) - quote - if isactive() - $(getfield(Juno, :Atom).Progress._progress(name, thresh, ex)) - else - $(esc(ex)) + if ex.head == :for && + ex.args[1].head == Symbol("=") && + ex.args[2].head == :block + x = esc(ex.args[1].args[1]) + range = esc(ex.args[1].args[2]) + body = esc(ex.args[2]) + quote + if isactive() + p = ProgressBar(name = $name) + progress(p, 0) + lastfrac = 0.0 + try + range = $range + n = length(range) + for (i, $x) in enumerate(range) + $body + + frac = i/n + if frac - lastfrac > $thresh + progress(p, i/n) + lastfrac = frac + end + end + finally + done(p) + end + else + $(esc(ex)) + end end + else + error("@progress requires a for loop") end end