Skip to content

Commit 0021ebb

Browse files
committed
allow for arbitrary exit keys to exit app_main_loop
1 parent be52111 commit 0021ebb

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/main_loop.jl

+16-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,26 @@
66

77
export app_main_loop
88

9+
"""
10+
check_keystroke(k1::Keystroke, k2::Keystroke) -> Bool
11+
check_keystroke(k1::Symbol, k2::Symbol) -> Bool
12+
check_keystroke(k1::Symbol, k2::Keystroke) -> Bool
13+
check_keystroke(k1::Keystroke, k2::Symbol) -> Bool
14+
15+
Evaluate if either keystroke.type or keystroke k1 and k2 match
16+
"""
17+
check_keystroke(k1::Keystroke, k2::Keystroke) = k1 == k2
18+
check_keystroke(k1::Symbol, k2::Symbol) = k1 == k2
19+
check_keystroke(k1::Keystroke, k2::Symbol) = k1.ktype == k2
20+
check_keystroke(k1::Symbol, k2::Keystroke) = k1 == k2.ktype
21+
22+
923
"""
1024
app_main_loop() -> Nothing
1125
1226
Start the application main loop.
1327
"""
14-
function app_main_loop()
28+
function app_main_loop(; exitkey = :F1)
1529
# If there is no window in focus, try to acquire it.
1630
isnothing(get_focused_window()) && move_focus_to_next_window()
1731

@@ -28,7 +42,7 @@ function app_main_loop()
2842

2943
# Check if the keystroke must be passed or if the signal hijacked it.
3044
if !@get_signal_property(tui, keypressed, block, false)
31-
if k.ktype == :F1
45+
if check_keystroke(k, exitkey)
3246
break
3347
else
3448
process_keystroke(k)

0 commit comments

Comments
 (0)