diff --git a/src/Live/app.jl b/src/Live/app.jl index b572cb43..bc1cfd81 100644 --- a/src/Live/app.jl +++ b/src/Live/app.jl @@ -35,26 +35,31 @@ other widgets to access their internal variables. help_message::Union{Nothing,String} should_stop::Bool - function AppInternals(; refresh_rate::Int = 60, help_message = nothing) + function AppInternals(; + refresh_rate::Int = 60, + help_message = nothing, + suppress_output = false, + ) # get output buffers iob = IOBuffer() ioc = IOContext(iob, :displaysize => displaysize(stdout)) # prepare terminal raw_mode_enabled = try - raw!(terminal, true) + raw!(get_terminal(), true) true catch err - @debug "Unable to enter raw mode: " exception = (err, catch_backtrace()) + suppress_output || + @warn "Unable to enter raw mode: " exception = (err, catch_backtrace()) false end # hide the cursor - raw_mode_enabled && print(terminal.out_stream, "\x1b[?25l") + raw_mode_enabled && print(get_terminal().out_stream, "\x1b[?25l") return new( iob, ioc, - terminal, + get_terminal(), nothing, String[], raw_mode_enabled, diff --git a/src/Live/keyboard_input.jl b/src/Live/keyboard_input.jl index e2b70630..9c95db41 100644 --- a/src/Live/keyboard_input.jl +++ b/src/Live/keyboard_input.jl @@ -7,9 +7,9 @@ if it exists. Returns a list of return values from the control functions. """ function keyboard_input(widget::AbstractWidget) controls = widget.controls - if bytesavailable(terminal.in_stream) > 0 + if bytesavailable(get_terminal().in_stream) > 0 # get input - c = readkey(terminal.in_stream) + c = readkey(get_terminal().in_stream) c = haskey(KEYs, Int(c)) ? KEYs[Int(c)] : Char(c) # see if a control has been defined for this key @@ -28,9 +28,9 @@ Get keyboard input from the terminal and execute the corresponding control funct """ function keyboard_input(widget::AbstractWidgetContainer) retvals = [] - if bytesavailable(terminal.in_stream) > 0 + if bytesavailable(get_terminal().in_stream) > 0 # get input - c = readkey(terminal.in_stream) + c = readkey(get_terminal().in_stream) c = haskey(KEYs, Int(c)) ? KEYs[Int(c)] : Char(c) # ::Union{Char, KeyInput} # execute command on each subwidget diff --git a/src/Live/live.jl b/src/Live/live.jl index efeef6f2..e8809f7f 100644 --- a/src/Live/live.jl +++ b/src/Live/live.jl @@ -2,10 +2,13 @@ module LiveWidgets import REPL import REPL.Terminals: raw!, AbstractTerminal import REPL.TerminalMenus: readkey -const terminal = @static if isdefined(REPL.TerminalMenus, :default_terminal) - REPL.TerminalMenus.default_terminal() -else - REPL.TerminalMenus.terminal + +function get_terminal() + return @static if isdefined(REPL.TerminalMenus, :default_terminal) + REPL.TerminalMenus.default_terminal() + else + REPL.TerminalMenus.terminal + end end using Dates