Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix live apps #258

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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