Skip to content

Commit

Permalink
Merge pull request #159 from JunoLab/sp/betterprogess
Browse files Browse the repository at this point in the history
better progress handling
  • Loading branch information
pfitzseb authored Aug 29, 2019
2 parents 68de1a6 + 342fad3 commit df94572
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ function modulesymbols(mod)
sort(syms, by = x -> x.name)[1:min(100, length(syms))]
end

using Logging: with_logger, current_logger
using Logging: with_logger
using .Progress: JunoProgressLogger

handle("regenerateCache") do
Base.CoreLogging.with_logger(Atom.Progress.JunoProgressLogger(Base.CoreLogging.current_logger())) do
with_logger(JunoProgressLogger()) do
@errs DocSeeker.createdocsdb()
end
end
8 changes: 4 additions & 4 deletions src/eval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using CodeTools, LNR, Media
using CodeTools: getthing, getmodule
import REPL

using Logging: with_logger, current_logger
using Logging: with_logger
using .Progress: JunoProgressLogger

ends_with_semicolon(x) = REPL.ends_with_semicolon(split(x,'\n',keepempty = false)[end])
Expand Down Expand Up @@ -56,7 +56,7 @@ handle("evalshow") do data

lock(evallock)
result = hideprompt() do
Base.CoreLogging.with_logger(Atom.Progress.JunoProgressLogger(Base.CoreLogging.current_logger())) do
with_logger(JunoProgressLogger()) do
withpath(path) do
try
res = include_string(mod, text, path, line)
Expand Down Expand Up @@ -89,7 +89,7 @@ handle("eval") do data

lock(evallock)
result = hideprompt() do
Base.CoreLogging.with_logger(Atom.Progress.JunoProgressLogger(Base.CoreLogging.current_logger())) do
with_logger(JunoProgressLogger()) do
withpath(path) do
@errs include_string(mod, text, path, line)
end
Expand Down Expand Up @@ -118,7 +118,7 @@ handle("evalall") do data

lock(evallock)
hideprompt() do
Base.CoreLogging.with_logger(Atom.Progress.JunoProgressLogger(Base.CoreLogging.current_logger())) do
with_logger(JunoProgressLogger()) do
withpath(path) do
result = nothing
try
Expand Down
25 changes: 13 additions & 12 deletions src/progress.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ using Atom: msg
const progs = Set()

"""
JunoProgressLogger(previous_logger<:AbstractLogger)
JunoProgressLogger()
Logger that only handles messages with `progress` argument set and passes all
others throught to the previously defined logger.
others through to the `global_logger`.
If the `progress` argument is set then a corresponding progress bar will be shown
in the Juno frontend with it's name set to the logging message.
If the `progress` argument is set, then a progress bar will be shown in the Juno frontend.
Possible keyword arguments to logging messages consumed by this logger are:
- `progress`:
Expand All @@ -23,9 +22,7 @@ Possible keyword arguments to logging messages consumed by this logger are:
- `message`: Shown in a tooltip.
- `_id`: The progress bars' ID. Should be set (to a symbol or string) in most cases.
"""
struct JunoProgressLogger <: AbstractLogger
previous_logger
end
struct JunoProgressLogger <: AbstractLogger end

function Logging.handle_message(j::JunoProgressLogger, level, message, _module,
group, id, file, line; kwargs...)
Expand Down Expand Up @@ -61,9 +58,11 @@ function Logging.handle_message(j::JunoProgressLogger, level, message, _module,
msg("progress", "message", id, kwargs[:message])
end
else
if (Logging.min_enabled_level(j.previous_logger) <= Logging.LogLevel(level) || Base.CoreLogging.env_override_minlevel(group, _module)) &&
Logging.shouldlog(j.previous_logger, level, _module, group, id)
Logging.handle_message(j.previous_logger, level, message, _module,
previous_logger = Logging.global_logger()
if (Logging.min_enabled_level(previous_logger) <= Logging.LogLevel(level) ||
Base.CoreLogging.env_override_minlevel(group, _module)) &&
Logging.shouldlog(previous_logger, level, _module, group, id)
Logging.handle_message(previous_logger, level, message, _module,
group, id, file, line; kwargs...)
end
end
Expand All @@ -73,5 +72,7 @@ Logging.shouldlog(::JunoProgressLogger, level, _module, group, id) = true

Logging.catch_exceptions(::JunoProgressLogger) = true

Logging.min_enabled_level(j::JunoProgressLogger) = min(Logging.min_enabled_level(j.previous_logger), Logging.LogLevel(-1))
end
Logging.min_enabled_level(j::JunoProgressLogger) =
min(Logging.min_enabled_level(Logging.global_logger()), Logging.LogLevel(-1))

end # module
4 changes: 3 additions & 1 deletion src/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ using REPL.LineEdit
# FIXME: Find a way to reprint what's currently entered in the REPL after changing
# the module (or delete it in the buffer).

using Logging: with_logger
using .Progress: JunoProgressLogger

function get_main_mode()
mode = Base.active_repl.interface.modes[1]
Expand Down Expand Up @@ -149,7 +151,7 @@ function evalrepl(mod, line)
fixjunodisplays()
# this is slow:
errored = false
Base.CoreLogging.with_logger(Atom.JunoProgressLogger(Base.CoreLogging.current_logger())) do
with_logger(JunoProgressLogger()) do
try
line = Meta.parse(line)
catch err
Expand Down

0 comments on commit df94572

Please sign in to comment.