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
This commit is contained in:
mgpinf authored and Wez Furlong committed 2025-05-11 09:54:57 -07:00
1 parent 5cab87d42e
commit cfd91c022e
1 file changed
+12 -6
+12 -6
View File
@@ -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;
}
_ => {}