From cfd91c022ee42ed9f931dce4adb791218e254485 Mon Sep 17 00:00:00 2001 From: mgpinf Date: Sat, 15 Mar 2025 23:59:18 +0530 Subject: [PATCH] feat: add additional key modifier combinations to exit polling input Add below key modifier combinations to exit polling input when hold option is set: * Ctrl-C * Ctrl-D * Escape --- wezterm/src/main.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/wezterm/src/main.rs b/wezterm/src/main.rs index b45a41e94..0661d803d 100644 --- a/wezterm/src/main.rs +++ b/wezterm/src/main.rs @@ -9,7 +9,7 @@ use std::io::Read; use termwiz::caps::Capabilities; use termwiz::escape::esc::{Esc, EscCode}; use termwiz::escape::OneBased; -use termwiz::input::{InputEvent, KeyCode, KeyEvent}; +use termwiz::input::{InputEvent, KeyCode, KeyEvent, Modifiers}; use termwiz::surface::change::Change; use termwiz::surface::Position; use termwiz::terminal::{ScreenSize, Terminal}; @@ -181,7 +181,7 @@ struct ImgCatCommand { #[arg(long)] no_move_cursor: bool, - /// Wait for enter to be pressed after displaying the image + /// Wait for enter/escape/ctrl-c/ctrl-d to be pressed after displaying the image #[arg(long)] hold: bool, @@ -590,10 +590,16 @@ impl ImgCatCommand { term.set_raw_mode()?; while let Ok(Some(event)) = term.poll_input(None) { match event { - InputEvent::Key(KeyEvent { - key: KeyCode::Enter, - modifiers: _, - }) => { + InputEvent::Key( + KeyEvent { + key: KeyCode::Enter | KeyCode::Escape, + modifiers: _, + } + | KeyEvent { + key: KeyCode::Char('c') | KeyCode::Char('d'), + modifiers: Modifiers::CTRL, + }, + ) => { break; } _ => {} -- 2.51.2