generated from GarandPLG/rust-flake-template
Add Quit2 action bound to Ctrl+C
This commit is contained in:
@@ -109,6 +109,7 @@ impl App {
|
||||
if let Some(action) = event_to_action(&key_event) {
|
||||
match action {
|
||||
Action::Quit => self.exit = true,
|
||||
Action::Quit2 => self.exit = true,
|
||||
Action::Esc => self.view = View::MainMenu,
|
||||
_ => (),
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum Action {
|
||||
Quit,
|
||||
Quit2,
|
||||
Up,
|
||||
Down,
|
||||
Space,
|
||||
@@ -50,6 +51,15 @@ pub static KEYBINDINGS: &[KeyBinding] = &[
|
||||
symbol: "q",
|
||||
description: "Quit",
|
||||
},
|
||||
KeyBinding {
|
||||
action: Action::Quit2,
|
||||
code: KeyCode::Char('c'),
|
||||
kind: KeyEventKind::Press,
|
||||
modifiers: KeyModifiers::CONTROL,
|
||||
group: Group::Quit,
|
||||
symbol: "Ctrl + c",
|
||||
description: "Quit",
|
||||
},
|
||||
KeyBinding {
|
||||
action: Action::Up,
|
||||
code: KeyCode::Up,
|
||||
@@ -106,9 +116,11 @@ pub fn binding_for_view(view: View) -> Vec<&'static KeyBinding> {
|
||||
binding_for(Action::Down).unwrap(),
|
||||
binding_for(Action::Space).unwrap(),
|
||||
binding_for(Action::Quit).unwrap(),
|
||||
binding_for(Action::Quit2).unwrap(),
|
||||
],
|
||||
_ => vec![
|
||||
binding_for(Action::Quit).unwrap(),
|
||||
binding_for(Action::Quit2).unwrap(),
|
||||
binding_for(Action::Esc).unwrap(),
|
||||
],
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ pub fn main_menu_keybindings(app: &mut App, event: &KeyEvent) {
|
||||
if let Some(action) = event_to_action(&event) {
|
||||
match action {
|
||||
Action::Quit => app.exit = true,
|
||||
Action::Quit2 => app.exit = true,
|
||||
Action::Up => {
|
||||
app.game_states.main_menu_state.selected_view = app
|
||||
.game_states
|
||||
|
||||
Reference in New Issue
Block a user