Skip to content

Commit

Permalink
Fix live apps (#258)
Browse files Browse the repository at this point in the history
* change const terminal to get_terminal() fn

in line with REPL.TerminalMenus

* changes warning from bebug to warn level

in line with REPL.TerminalMenus

---------

Co-authored-by: sandyspiers <sandy.spiers@gmail.edu.au>
  • Loading branch information
sandyspiers and sandyspiers authored Jan 13, 2025
1 parent 3b13ca7 commit 71c4449
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
15 changes: 10 additions & 5 deletions src/Live/app.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/Live/keyboard_input.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 7 additions & 4 deletions src/Live/live.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 71c4449

Please sign in to comment.