From 7aa80c230f06b68eb4e9aa618938b8cb5a562c90 Mon Sep 17 00:00:00 2001 From: srdusr Date: Fri, 8 Mar 2024 20:05:27 +0200 Subject: Quit the game or go back to the main menu functionality added instead of just quitting the game --- src/main.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 6fbd3e0..6a4bcba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -171,9 +171,16 @@ async fn input_handler(event: KeyEvent, app: &mut App, _event_tx: Arc> KeyCode::Backspace => { app.input_string.pop(); } - KeyCode::Esc => { - app.should_exit = true; - } + KeyCode::Esc => match app.state { + State::MainMenu => { + app.should_exit = true; + } + State::TypingGame | State::EndScreen => { + app.state = State::MainMenu; + app.input_string.clear(); + app.timer = None; + } + }, KeyCode::Enter => match app.state { State::MainMenu => { app.state = State::TypingGame; @@ -198,14 +205,12 @@ async fn input_handler(event: KeyEvent, app: &mut App, _event_tx: Arc> #[cfg(test)] mod test; +// Main function #[tokio::main] async fn main() -> Result<(), io::Error> { // Enable raw mode for terminal input enable_raw_mode()?; - // Print current working directory - println!("Current working directory: {:?}", std::env::current_dir()); - // Create a new instance of the App let mut app = App::new().unwrap(); -- cgit v1.2.3