Skip to content

allow for arbitrary exit keys to exit app_main_loop #16

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

Merged
merged 1 commit into from
Apr 25, 2024
Merged
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
18 changes: 16 additions & 2 deletions src/main_loop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,26 @@

export app_main_loop

"""
check_keystroke(k1::Keystroke, k2::Keystroke) -> Bool
check_keystroke(k1::Symbol, k2::Symbol) -> Bool
check_keystroke(k1::Symbol, k2::Keystroke) -> Bool
check_keystroke(k1::Keystroke, k2::Symbol) -> Bool

Evaluate if either keystroke.type or keystroke k1 and k2 match
"""
check_keystroke(k1::Keystroke, k2::Keystroke) = k1 == k2
check_keystroke(k1::Symbol, k2::Symbol) = k1 == k2
check_keystroke(k1::Keystroke, k2::Symbol) = k1.ktype == k2
check_keystroke(k1::Symbol, k2::Keystroke) = k1 == k2.ktype


"""
app_main_loop() -> Nothing

Start the application main loop.
"""
function app_main_loop()
function app_main_loop(; exitkey = :F1)
# If there is no window in focus, try to acquire it.
isnothing(get_focused_window()) && move_focus_to_next_window()

Expand All @@ -28,7 +42,7 @@ function app_main_loop()

# Check if the keystroke must be passed or if the signal hijacked it.
if !@get_signal_property(tui, keypressed, block, false)
if k.ktype == :F1
if check_keystroke(k, exitkey)
break
else
process_keystroke(k)
Expand Down