From 6cd286fd66f7bd716f68ab962569d48a4e2a5334 Mon Sep 17 00:00:00 2001 From: Jeff Nunn Date: Sat, 22 Nov 2025 16:05:45 -0600 Subject: [PATCH] Binds to quit in contexts where q or ctrl+c is accepted as quit (#98) --- Readme.md | 3 ++- src/config.rs | 7 +++++++ src/handler.rs | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 8c7ed38..8ef85c6 100644 --- a/Readme.md +++ b/Readme.md @@ -77,7 +77,7 @@ This will produce an executable file at `target/release/bluetui` that you can co `s`: Start/Stop scanning. -`ctrl+c` or `q`: Quit the app. +`ctrl+c` or `q`: Quit the app. (Note: `` can also quit if `esc_quit = true` is set in config) ### Adapters @@ -114,6 +114,7 @@ layout = "SpaceAround" width = "auto" toggle_scanning = "s" +esc_quit = false # Set to true to enable Esc key to quit the app [adapter] toggle_pairing = "p" diff --git a/src/config.rs b/src/config.rs index 3041a62..6d28ef1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -21,6 +21,9 @@ pub struct Config { #[serde(default = "default_toggle_scanning")] pub toggle_scanning: char, + #[serde(default = "default_esc_quit")] + pub esc_quit: bool, + #[serde(default)] pub adapter: Adapter, @@ -166,6 +169,10 @@ fn default_toggle_scanning() -> char { 's' } +fn default_esc_quit() -> bool { + false +} + fn default_toggle_adapter_pairing() -> char { 'p' } diff --git a/src/handler.rs b/src/handler.rs index 28165d2..9dc245c 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -268,6 +268,10 @@ pub async fn handle_key_events( app.quit(); } + KeyCode::Esc if app.config.esc_quit => { + app.quit(); + } + // Switch focus KeyCode::Tab | KeyCode::Char('l') => match app.focused_block { FocusedBlock::Adapter => {