mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-12 20:23:35 +00:00
Move ctrl-C handling from backend to cursive callbacks
This commit is contained in:
parent
54882989e4
commit
5afefb8645
@ -98,10 +98,6 @@ impl From<CKeyEvent> for Event {
|
|||||||
|
|
||||||
match event {
|
match event {
|
||||||
// Handle Char + modifier.
|
// Handle Char + modifier.
|
||||||
CKeyEvent {
|
|
||||||
modifiers: KeyModifiers::CONTROL,
|
|
||||||
code: KeyCode::Char('c'),
|
|
||||||
} => Event::Exit,
|
|
||||||
CKeyEvent {
|
CKeyEvent {
|
||||||
modifiers: KeyModifiers::CONTROL,
|
modifiers: KeyModifiers::CONTROL,
|
||||||
code: KeyCode::Char(c),
|
code: KeyCode::Char(c),
|
||||||
|
@ -509,7 +509,6 @@ fn initialize_keymap() -> HashMap<i32, Event> {
|
|||||||
let event = match c {
|
let event = match c {
|
||||||
// This is Ctrl+C
|
// This is Ctrl+C
|
||||||
// TODO: Don't exit here, but add this as a default callback
|
// TODO: Don't exit here, but add this as a default callback
|
||||||
3 => Event::Exit,
|
|
||||||
9 => Event::Key(Key::Tab),
|
9 => Event::Key(Key::Tab),
|
||||||
10 => Event::Key(Key::Enter),
|
10 => Event::Key(Key::Enter),
|
||||||
other => Event::CtrlChar((b'a' - 1 + other as u8) as char),
|
other => Event::CtrlChar((b'a' - 1 + other as u8) as char),
|
||||||
|
@ -151,8 +151,6 @@ impl Backend {
|
|||||||
pancurses::Input::Character('\u{9}') => Event::Key(Key::Tab),
|
pancurses::Input::Character('\u{9}') => Event::Key(Key::Tab),
|
||||||
pancurses::Input::Character('\u{1b}') => Event::Key(Key::Esc),
|
pancurses::Input::Character('\u{1b}') => Event::Key(Key::Esc),
|
||||||
// Ctrl+C
|
// 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 => {
|
pancurses::Input::Character(c) if (c as u32) <= 26 => {
|
||||||
Event::CtrlChar((b'a' - 1 + c as u8) as char)
|
Event::CtrlChar((b'a' - 1 + c as u8) as char)
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,6 @@ impl Backend {
|
|||||||
TEvent::Key(TKey::Char('\n')) => Event::Key(Key::Enter),
|
TEvent::Key(TKey::Char('\n')) => Event::Key(Key::Enter),
|
||||||
TEvent::Key(TKey::Char('\t')) => Event::Key(Key::Tab),
|
TEvent::Key(TKey::Char('\t')) => Event::Key(Key::Tab),
|
||||||
TEvent::Key(TKey::Char(c)) => Event::Char(c),
|
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::Ctrl(c)) => Event::CtrlChar(c),
|
||||||
TEvent::Key(TKey::Alt(c)) => Event::AltChar(c),
|
TEvent::Key(TKey::Alt(c)) => Event::AltChar(c),
|
||||||
TEvent::Mouse(TMouseEvent::Press(btn, x, y)) => {
|
TEvent::Mouse(TMouseEvent::Press(btn, x, y)) => {
|
||||||
|
@ -150,7 +150,8 @@ impl Cursive {
|
|||||||
|
|
||||||
let (cb_sink, cb_source) = crossbeam_channel::unbounded();
|
let (cb_sink, cb_source) = crossbeam_channel::unbounded();
|
||||||
|
|
||||||
backend_init().map(|backend| Cursive {
|
let backend = backend_init()?;
|
||||||
|
let mut cursive = Cursive {
|
||||||
theme,
|
theme,
|
||||||
root: views::OnEventView::new(views::ScreensView::single_screen(
|
root: views::OnEventView::new(views::ScreensView::single_screen(
|
||||||
views::StackView::new(),
|
views::StackView::new(),
|
||||||
@ -164,7 +165,10 @@ impl Cursive {
|
|||||||
fps: None,
|
fps: None,
|
||||||
boring_frame_count: 0,
|
boring_frame_count: 0,
|
||||||
user_data: Box::new(()),
|
user_data: Box::new(()),
|
||||||
})
|
};
|
||||||
|
cursive.reset_default_callbacks();
|
||||||
|
|
||||||
|
Ok(cursive)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new Cursive root using a ncurses backend.
|
/// Creates a new Cursive root using a ncurses backend.
|
||||||
|
Loading…
Reference in New Issue
Block a user