From 3a519faa4a2f7654b5aed326d599c766703c7485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cserteg=20Tam=C3=A1s?= Date: Thu, 11 Jul 2019 13:17:57 +0200 Subject: [PATCH 1/2] add nicer status messages when something printed between start and end --- src/manager/judoc.jl | 14 +++++++++----- src/manager/post_processing.jl | 27 ++++++++++++++++----------- src/misc_utils.jl | 15 ++++++++++++--- test/misc.jl | 2 +- 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/manager/judoc.jl b/src/manager/judoc.jl index 2ac9637c9..11afac56d 100644 --- a/src/manager/judoc.jl +++ b/src/manager/judoc.jl @@ -38,7 +38,8 @@ function serve(; clear::Bool=true, verb::Bool=false, port::Int=8000, single::Boo start = time() sig = jd_fullpass(watched_files; clear=clear, verb=verb, prerender=prerender, isoptim=isoptim) sig < 0 && return sig - verb && (print(rpad("\n✔ full pass...", 40)); time_it_took(start); println("")) + fmsg = rpad("✔ full pass...", 40) + verb && (println(""); print(fmsg); printend(fmsg, start); println("")) # start the continuous loop if !single @@ -179,16 +180,19 @@ function jd_loop(cycle_counter::Int, ::LiveServer.FileWatcher, watched_files::Na cur_t = mtime(fpath) cur_t <= t && continue # if there was then the file has been modified and should be re-processed + copied - verb && print(rpad("→ file $(fpath[length(FOLDER_PATH[])+1:end]) was modified ", 30)) + fmsg = rpad("→ file $(fpath[length(FOLDER_PATH[])+1:end]) was modified ", 30) + verb && print(fmsg) dict[fpair] = cur_t # if it's an infra_file if haskey(watched_files[:infra], fpair) + #TODO: couldn't test this branch verb && println("→ full pass...") start = time() jd_fullpass(watched_files; clear=false, verb=false, prerender=false) - verb && (print(rpad("\n✔ full pass...", 15)); time_it_took(start); println("")) + verb && (printend(rpad("✔ full pass...", 15), start); println("")) else - verb && print(rpad("→ updating... ", 15)) + fmsg = fmsg * rpad("→ updating... ", 15) + verb && print("\r" * fmsg) start = time() # TODO, ideally these would only be read if they've changed. Not super important # but just not necessary. (Fixing may be a bit of a pain though) @@ -196,7 +200,7 @@ function jd_loop(cycle_counter::Int, ::LiveServer.FileWatcher, watched_files::Na pg_foot = read(joinpath(PATHS[:src_html], "page_foot.html"), String) foot = read(joinpath(PATHS[:src_html], "foot.html"), String) process_file(case, fpair, head, pg_foot, foot, cur_t; clear=false, prerender=false) - verb && time_it_took(start) + verb && printend(fmsg, start) end end end diff --git a/src/manager/post_processing.jl b/src/manager/post_processing.jl index 84b3141eb..75def0c69 100644 --- a/src/manager/post_processing.jl +++ b/src/manager/post_processing.jl @@ -31,11 +31,12 @@ function optimize(; prerender::Bool=true, minify::Bool=true, sig::Bool=false, end # re-do a (silent) full pass start = time() - print("→ Full pass") - withpre = ifelse(prerender, rpad(" (with pre-rendering)", 24), rpad(" (no pre-rendering)", 24)) + fmsg = "\r→ Full pass" + print(fmsg) + withpre = fmsg * ifelse(prerender, rpad(" (with pre-rendering)", 24), rpad(" (no pre-rendering)", 24)) print(withpre) succ = (serve(single=true, prerender=prerender, nomess=true, isoptim=true) === nothing) - time_it_took(start) + printend(withpre, start) # # Minification @@ -43,14 +44,15 @@ function optimize(; prerender::Bool=true, minify::Bool=true, sig::Bool=false, if minify && succ if JD_CAN_MINIFY start = time() - print(rpad("→ Minifying *.[html|css] files...", 35)) + mmsg = rpad("→ Minifying *.[html|css] files...", 35) + print(mmsg) # copy the script to the current dir cp(joinpath(dirname(pathof(JuDoc)), "scripts", "minify.py"), JD_PY_MIN_NAME; force=true) # run it succ = success(`$([e for e in split(PY)]) $JD_PY_MIN_NAME`) # remove the script file rm(JD_PY_MIN_NAME) - time_it_took(start) + printend(mmsg, start) else @warn "I didn't find css_html_js_minify, you can install it via pip the output will "* "not be minified." @@ -82,12 +84,13 @@ function publish(; prerender::Bool=true, minify::Bool=true, nopass::Bool=false, end if succ start = time() - print(rpad("→ Pushing updates with git...", 35)) + pubmsg = rpad("→ Pushing updates with git...", 35) + print(pubmsg) try run(`git add -A `) run(`git commit -m "jd-update" --quiet`) run(`git push --quiet`) - time_it_took(start) + printend(pubmsg, start) catch e println("✘ Could not push updates, verify your connection and try manually.\n") @show e @@ -109,14 +112,16 @@ function cleanpull()::Nothing FOLDER_PATH[] = pwd() set_paths!() if isdir(PATHS[:pub]) - print(rpad("→ Removing local output dir...", 35)) + rmmsg = rpad("→ Removing local output dir...", 35) + print(rmmsg) rm(PATHS[:pub], force=true, recursive=true) - println(" [done ✔ ]") + println("\r" * rmmsg * " [done ✔ ]") end try - print(rpad("→ Retrieving updates from the repository...", 35)) + pmsg = rpad("→ Retrieving updates from the repository...", 35) + print(pmsg) run(`git pull --quiet`) - println(" [done ✔ ]") + println("\r" * pmsg * " [done ✔ ]") catch e println("✘ Could not pull updates, verify your connection and try manually.\n") @show e diff --git a/src/misc_utils.jl b/src/misc_utils.jl index 454df11be..514da5b77 100644 --- a/src/misc_utils.jl +++ b/src/misc_utils.jl @@ -88,13 +88,22 @@ $(SIGNATURES) Convenience function to display a time since `start`. """ -function time_it_took(start::Float64)::Nothing +function time_it_took(start::Float64) comp_time = time() - start mess = comp_time > 60 ? "$(round(comp_time/60; digits=1))m" : comp_time > 1 ? "$(round(comp_time; digits=1))s" : "$(round(comp_time*1000; digits=1))ms" - println("[done $(lpad(mess, 6))]") - return nothing + return "[done $(lpad(mess, 6))]" +end + +``` +$(SIGNATURES) + +Nicer printing of processes. +``` +function printend(startmsg::AbstractString, starttime::Float64)::Nothing + tit = time_it_took(starttime) + println("\r$startmsg$tit") end diff --git a/test/misc.jl b/test/misc.jl index ce55db3bb..ff25ce540 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -67,7 +67,7 @@ end f = joinpath(d, "a.txt") open(f, "w") do outf redirect_stdout(outf) do - J.time_it_took(start) + J.printend("elapsing",start) end end r = read(f, String) From c8750f154ff90fdb2dcbe551d4ecc14911670b8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cserteg=20Tam=C3=A1s?= Date: Thu, 11 Jul 2019 14:57:05 +0200 Subject: [PATCH 2/2] rename printend to print_final --- src/manager/judoc.jl | 6 +++--- src/manager/post_processing.jl | 6 +++--- src/misc_utils.jl | 2 +- test/misc.jl | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/manager/judoc.jl b/src/manager/judoc.jl index 11afac56d..8c4743577 100644 --- a/src/manager/judoc.jl +++ b/src/manager/judoc.jl @@ -39,7 +39,7 @@ function serve(; clear::Bool=true, verb::Bool=false, port::Int=8000, single::Boo sig = jd_fullpass(watched_files; clear=clear, verb=verb, prerender=prerender, isoptim=isoptim) sig < 0 && return sig fmsg = rpad("✔ full pass...", 40) - verb && (println(""); print(fmsg); printend(fmsg, start); println("")) + verb && (println(""); print(fmsg); print_final(fmsg, start); println("")) # start the continuous loop if !single @@ -189,7 +189,7 @@ function jd_loop(cycle_counter::Int, ::LiveServer.FileWatcher, watched_files::Na verb && println("→ full pass...") start = time() jd_fullpass(watched_files; clear=false, verb=false, prerender=false) - verb && (printend(rpad("✔ full pass...", 15), start); println("")) + verb && (print_final(rpad("✔ full pass...", 15), start); println("")) else fmsg = fmsg * rpad("→ updating... ", 15) verb && print("\r" * fmsg) @@ -200,7 +200,7 @@ function jd_loop(cycle_counter::Int, ::LiveServer.FileWatcher, watched_files::Na pg_foot = read(joinpath(PATHS[:src_html], "page_foot.html"), String) foot = read(joinpath(PATHS[:src_html], "foot.html"), String) process_file(case, fpair, head, pg_foot, foot, cur_t; clear=false, prerender=false) - verb && printend(fmsg, start) + verb && print_final(fmsg, start) end end end diff --git a/src/manager/post_processing.jl b/src/manager/post_processing.jl index 75def0c69..7100f1075 100644 --- a/src/manager/post_processing.jl +++ b/src/manager/post_processing.jl @@ -36,7 +36,7 @@ function optimize(; prerender::Bool=true, minify::Bool=true, sig::Bool=false, withpre = fmsg * ifelse(prerender, rpad(" (with pre-rendering)", 24), rpad(" (no pre-rendering)", 24)) print(withpre) succ = (serve(single=true, prerender=prerender, nomess=true, isoptim=true) === nothing) - printend(withpre, start) + print_final(withpre, start) # # Minification @@ -52,7 +52,7 @@ function optimize(; prerender::Bool=true, minify::Bool=true, sig::Bool=false, succ = success(`$([e for e in split(PY)]) $JD_PY_MIN_NAME`) # remove the script file rm(JD_PY_MIN_NAME) - printend(mmsg, start) + print_final(mmsg, start) else @warn "I didn't find css_html_js_minify, you can install it via pip the output will "* "not be minified." @@ -90,7 +90,7 @@ function publish(; prerender::Bool=true, minify::Bool=true, nopass::Bool=false, run(`git add -A `) run(`git commit -m "jd-update" --quiet`) run(`git push --quiet`) - printend(pubmsg, start) + print_final(pubmsg, start) catch e println("✘ Could not push updates, verify your connection and try manually.\n") @show e diff --git a/src/misc_utils.jl b/src/misc_utils.jl index 514da5b77..45ae2b1ed 100644 --- a/src/misc_utils.jl +++ b/src/misc_utils.jl @@ -101,7 +101,7 @@ $(SIGNATURES) Nicer printing of processes. ``` -function printend(startmsg::AbstractString, starttime::Float64)::Nothing +function print_final(startmsg::AbstractString, starttime::Float64)::Nothing tit = time_it_took(starttime) println("\r$startmsg$tit") end diff --git a/test/misc.jl b/test/misc.jl index ff25ce540..f41b6e2c8 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -67,7 +67,7 @@ end f = joinpath(d, "a.txt") open(f, "w") do outf redirect_stdout(outf) do - J.printend("elapsing",start) + J.print_final("elapsing",start) end end r = read(f, String)