From 330c8e8c1f552346f30ec34a3dc425eb7c45fd49 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 27 May 2019 16:17:49 -0700 Subject: [PATCH] lineedit: add ctrl-d -> EOF --- termwiz/src/lineedit/actions.rs | 1 + termwiz/src/lineedit/mod.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/termwiz/src/lineedit/actions.rs b/termwiz/src/lineedit/actions.rs index ba2ab1b53..c1382f71b 100644 --- a/termwiz/src/lineedit/actions.rs +++ b/termwiz/src/lineedit/actions.rs @@ -14,6 +14,7 @@ pub enum Movement { pub enum Action { AcceptLine, Cancel, + EndOfFile, InsertChar(RepeatCount, char), InsertText(RepeatCount, String), Repaint, diff --git a/termwiz/src/lineedit/mod.rs b/termwiz/src/lineedit/mod.rs index d88ce9013..5f075f603 100644 --- a/termwiz/src/lineedit/mod.rs +++ b/termwiz/src/lineedit/mod.rs @@ -26,6 +26,7 @@ //! Ctrl-E, End | Move cursor to the end of the line //! Ctrl-B, Left | Move cursor one grapheme to the left //! Ctrl-C | Cancel the line editor +//! Ctrl-D | Cancel the line editor with an End-of-File result //! Ctrl-F, Right | Move cursor one grapheme to the right //! Ctrl-H, Backspace | Delete the grapheme to the left of the cursor //! Ctrl-J, Ctrl-M, Enter | Finish line editing and accept the current line @@ -171,6 +172,12 @@ impl LineEditor { key: KeyCode::Char('C'), modifiers: Modifiers::CTRL, }) => Some(Action::Cancel), + + InputEvent::Key(KeyEvent { + key: KeyCode::Char('D'), + modifiers: Modifiers::CTRL, + }) => Some(Action::EndOfFile), + InputEvent::Key(KeyEvent { key: KeyCode::Char('J'), modifiers: Modifiers::CTRL, @@ -409,6 +416,13 @@ impl LineEditor { match self.resolve_action(&event) { Some(Action::Cancel) => return Ok(None), Some(Action::AcceptLine) => break, + Some(Action::EndOfFile) => { + return Err(std::io::Error::new( + std::io::ErrorKind::UnexpectedEof, + "End Of File", + ) + .into()) + } Some(Action::Kill(movement)) => self.kill_text(movement), Some(Action::Move(movement)) => self.cursor = self.eval_movement(movement), Some(Action::InsertChar(rep, c)) => {