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

allow for arbitrary exit keys to exit app_main_loop #16

Merged
merged 1 commit into from
Apr 25, 2024

Conversation

mdpetters
Copy link
Contributor

This change allows the use of any key when exiting the main loop. For example:

app_main_loop(exitkey = Keystroke(Int32(27), "\e", :esc, false, false, false))

uses ESC as the exit key. It is handled as a keyword, so the default "F1" exit behavior of

app_main_loop()

is unchanged.

@ronisbr
Copy link
Owner

ronisbr commented Apr 24, 2024

Hi @mdpetters !

Awesome! However, let me provide a suggestion. I think it will be cumbersome to ask for the user to define the structure Keystroke for the key they want (notice that it is necessary to correctly define all the fields). What if we create a function keyword called something like check_exit_keystroke. This function will have the following API:

check_exit_keystroke(k::Keystroke) -> Bool

If it returns true, the loop ends. Hence, the user can do something like this:

app_main_loop(; check_exit_keystroke = (k) -> k.ktype == :esc)

To exit on ESC for example.

What do you think?

@mdpetters
Copy link
Contributor Author

I think it makes sense to keep it simple along the lines you suggest. However, it would be nice to have complete keystroke support if needed. The updated code can check for equality of either the entire keystroke or just the ktype. This way the user has the choice.

@ronisbr
Copy link
Owner

ronisbr commented Apr 25, 2024

Awesome! Thanks!

@ronisbr ronisbr merged commit 9ad116d into ronisbr:master Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants