From 5d6456b582910fa81e40d093170842839839b066 Mon Sep 17 00:00:00 2001 From: shy Date: Thu, 22 Apr 2021 10:13:26 +0200 Subject: [PATCH] Handle '^\'. Minor code cleanup. --- src/lib.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8db960b..e001f58 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -290,9 +290,7 @@ pub fn run( force_redraw = true; } // Forward every char if in insert mode. - Key::Char(c) if buffer.visible => { - buffer.push(c); - } + Key::Char(c) if buffer.visible => buffer.push(c), // Reset clock on 'r'. Key::Char('r') => { clock.reset(); @@ -322,25 +320,19 @@ pub fn run( } // Exit on q and ^C. Key::Char('q') | Key::Ctrl('c') => break, + // Exit immediately on ^\. + Key::Ctrl('4') => process::exit(1), // Force redraw on ^R. Key::Ctrl('r') => force_redraw = true, // Suspend an ^Z. Key::Ctrl('z') => { suspend(&mut stdout)?; - // Clear SIGCONT, as we have already taken care to reset - // the terminal. - //signal.compare_and_swap(SIGCONT, 0, Ordering::Relaxed); force_redraw = true; - // Jump to the start of the main loop. - continue; } Key::Char(c) => { if c.is_ascii_digit() { buffer.push(c); buffer.visible = true; - force_redraw = true; - } else if !buffer.is_empty() && c == ':' { - buffer.push(':'); } } // Any other key. @@ -429,7 +421,7 @@ fn suspend(stdout: &mut RawTerminal) -> Result<(), std::io::Error> ); }); - if let Err(error) = low_level::emulate_default_handler(SIGTSTP as i32) { + if let Err(error) = low_level::emulate_default_handler(SIGSTOP as i32) { eprintln!("Error raising SIGTSTP: {}", error); }