Can press 'Esc' key to close windows
This commit is contained in:
		| @@ -69,7 +69,7 @@ impl GameRulesConfigurationScreen { | ||||
|                 if let Event::Key(key) = event::read()? { | ||||
|                     match key.code { | ||||
|                         // Quit app | ||||
|                         KeyCode::Char('q') => return Ok(ScreenResult::Canceled), | ||||
|                         KeyCode::Char('q') | KeyCode::Esc => return Ok(ScreenResult::Canceled), | ||||
|  | ||||
|                         // Navigate between fields | ||||
|                         KeyCode::Up | KeyCode::Left => cursor_pos -= 1, | ||||
|   | ||||
| @@ -18,6 +18,7 @@ use crate::ui_widgets::button_widget::ButtonWidget; | ||||
| pub fn confirm<B: Backend>(terminal: &mut Terminal<B>, msg: &str) -> bool { | ||||
|     matches!( | ||||
|         ConfirmDialogScreen::new(msg) | ||||
|             .set_can_escape(true) | ||||
|             .show(terminal) | ||||
|             .unwrap_or(ScreenResult::Canceled), | ||||
|         ScreenResult::Ok(true) | ||||
| @@ -41,6 +42,11 @@ impl<'a> ConfirmDialogScreen<'a> { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     pub fn set_can_escape(mut self, v: bool) -> Self { | ||||
|         self.can_escape = v; | ||||
|         self | ||||
|     } | ||||
|  | ||||
|     pub fn show<B: Backend>( | ||||
|         mut self, | ||||
|         terminal: &mut Terminal<B>, | ||||
|   | ||||
| @@ -147,7 +147,7 @@ impl GameScreen { | ||||
|  | ||||
|                     match key.code { | ||||
|                         // Leave game | ||||
|                         KeyCode::Char('q') | ||||
|                         KeyCode::Char('q') | KeyCode::Esc | ||||
|                             if confirm(terminal, "Do you really want to leave game?") => | ||||
|                         { | ||||
|                             self.client.close_connection().await; | ||||
|   | ||||
| @@ -52,7 +52,7 @@ impl<'a> PopupScreen<'a> { | ||||
|             if event::poll(timeout)? { | ||||
|                 if let Event::Key(key) = event::read()? { | ||||
|                     match key.code { | ||||
|                         KeyCode::Char('q') => return Ok(ScreenResult::Canceled), | ||||
|                         KeyCode::Char('q') | KeyCode::Esc => return Ok(ScreenResult::Canceled), | ||||
|                         KeyCode::Enter => { | ||||
|                             return Ok(ScreenResult::Ok(())); | ||||
|                         } | ||||
|   | ||||
| @@ -49,7 +49,7 @@ impl SelectBotTypeScreen { | ||||
|             if event::poll(timeout)? { | ||||
|                 if let Event::Key(key) = event::read()? { | ||||
|                     match key.code { | ||||
|                         KeyCode::Char('q') => return Ok(ScreenResult::Canceled), | ||||
|                         KeyCode::Char('q') | KeyCode::Esc => return Ok(ScreenResult::Canceled), | ||||
|                         KeyCode::Enter => { | ||||
|                             return Ok(ScreenResult::Ok(self.types[self.curr_selection].r#type)); | ||||
|                         } | ||||
|   | ||||
| @@ -92,7 +92,7 @@ impl SelectPlayModeScreen { | ||||
|             if crossterm::event::poll(timeout)? { | ||||
|                 if let Event::Key(key) = event::read()? { | ||||
|                     match key.code { | ||||
|                         KeyCode::Char('q') => return Ok(ScreenResult::Canceled), | ||||
|                         KeyCode::Char('q') | KeyCode::Esc => return Ok(ScreenResult::Canceled), | ||||
|                         KeyCode::Enter => { | ||||
|                             return Ok(ScreenResult::Ok( | ||||
|                                 AVAILABLE_PLAY_MODES[self.curr_selection].value, | ||||
|   | ||||
| @@ -66,7 +66,7 @@ impl<'a> SetBoatsLayoutScreen<'a> { | ||||
|                 let event = event::read()?; | ||||
|                 if let Event::Key(key) = &event { | ||||
|                     match key.code { | ||||
|                         KeyCode::Char('q') => { | ||||
|                         KeyCode::Char('q') | KeyCode::Esc => { | ||||
|                             if !self.confirm_on_cancel | ||||
|                                 || confirm(terminal, "Do you really want to quit?") | ||||
|                             { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user