From fe660228f2bcce262a7e18b4ced25736778b1eeb Mon Sep 17 00:00:00 2001 From: srdusr <99972264+srdusr@users.noreply.github.com> Date: Tue, 22 Jul 2025 10:05:00 +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/main.rs') 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