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 2025-03-15 23:59:18 +05:30 committed by Wez Furlong
parent 5cab87d42e
commit cfd91c022e

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;
}
_ => {}