aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsrdusr <trevorgray@srdusr.com>2024-03-08 20:05:27 +0200
committersrdusr <trevorgray@srdusr.com>2024-03-08 20:05:27 +0200
commit7aa80c230f06b68eb4e9aa618938b8cb5a562c90 (patch)
tree4dad7f9cce781fd11d7dfe0433a252c6f1900b23
parentd7e7322fddd4a8485bd3b08a22214d0b1153c686 (diff)
downloadtyperpunk-7aa80c230f06b68eb4e9aa618938b8cb5a562c90.tar.gz
typerpunk-7aa80c230f06b68eb4e9aa618938b8cb5a562c90.zip
Quit the game or go back to the main menu functionality added instead of just quitting the game
-rw-r--r--src/main.rs17
1 files changed, 11 insertions, 6 deletions
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<Mutex<()>>
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<Mutex<()>>
#[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();