From 5afefb8645cde743c0910c2d0b6133751d0772c1 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Sun, 26 Jan 2020 14:51:34 -0800 Subject: [PATCH] Move ctrl-C handling from backend to cursive callbacks --- src/backend/crossterm.rs | 4 ---- src/backend/curses/n.rs | 1 - src/backend/curses/pan.rs | 2 -- src/backend/termion.rs | 1 - src/cursive.rs | 8 ++++++-- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/backend/crossterm.rs b/src/backend/crossterm.rs index 7b5bf31..86ef78c 100644 --- a/src/backend/crossterm.rs +++ b/src/backend/crossterm.rs @@ -98,10 +98,6 @@ impl From for Event { match event { // Handle Char + modifier. - CKeyEvent { - modifiers: KeyModifiers::CONTROL, - code: KeyCode::Char('c'), - } => Event::Exit, CKeyEvent { modifiers: KeyModifiers::CONTROL, code: KeyCode::Char(c), diff --git a/src/backend/curses/n.rs b/src/backend/curses/n.rs index abd5794..0c74553 100644 --- a/src/backend/curses/n.rs +++ b/src/backend/curses/n.rs @@ -509,7 +509,6 @@ fn initialize_keymap() -> HashMap { let event = match c { // This is Ctrl+C // TODO: Don't exit here, but add this as a default callback - 3 => Event::Exit, 9 => Event::Key(Key::Tab), 10 => Event::Key(Key::Enter), other => Event::CtrlChar((b'a' - 1 + other as u8) as char), diff --git a/src/backend/curses/pan.rs b/src/backend/curses/pan.rs index fab6a85..ab22d76 100644 --- a/src/backend/curses/pan.rs +++ b/src/backend/curses/pan.rs @@ -151,8 +151,6 @@ impl Backend { pancurses::Input::Character('\u{9}') => Event::Key(Key::Tab), pancurses::Input::Character('\u{1b}') => Event::Key(Key::Esc), // Ctrl+C - // TODO: Do not sent Exit here, but register it as a default callback - pancurses::Input::Character('\u{3}') => Event::Exit, pancurses::Input::Character(c) if (c as u32) <= 26 => { Event::CtrlChar((b'a' - 1 + c as u8) as char) } diff --git a/src/backend/termion.rs b/src/backend/termion.rs index 4fb8957..5551743 100644 --- a/src/backend/termion.rs +++ b/src/backend/termion.rs @@ -120,7 +120,6 @@ impl Backend { TEvent::Key(TKey::Char('\n')) => Event::Key(Key::Enter), TEvent::Key(TKey::Char('\t')) => Event::Key(Key::Tab), TEvent::Key(TKey::Char(c)) => Event::Char(c), - TEvent::Key(TKey::Ctrl('c')) => Event::Exit, TEvent::Key(TKey::Ctrl(c)) => Event::CtrlChar(c), TEvent::Key(TKey::Alt(c)) => Event::AltChar(c), TEvent::Mouse(TMouseEvent::Press(btn, x, y)) => { diff --git a/src/cursive.rs b/src/cursive.rs index ba5c7b6..27aaa98 100644 --- a/src/cursive.rs +++ b/src/cursive.rs @@ -150,7 +150,8 @@ impl Cursive { let (cb_sink, cb_source) = crossbeam_channel::unbounded(); - backend_init().map(|backend| Cursive { + let backend = backend_init()?; + let mut cursive = Cursive { theme, root: views::OnEventView::new(views::ScreensView::single_screen( views::StackView::new(), @@ -164,7 +165,10 @@ impl Cursive { fps: None, boring_frame_count: 0, user_data: Box::new(()), - }) + }; + cursive.reset_default_callbacks(); + + Ok(cursive) } /// Creates a new Cursive root using a ncurses backend.