diff options
| author | mo8it <mo8it@proton.me> | 2024-04-30 01:46:57 +0200 |
|---|---|---|
| committer | mo8it <mo8it@proton.me> | 2024-04-30 01:46:57 +0200 |
| commit | 2b7ac915059a4baa2d9c86a583c73fc4f07a8775 (patch) | |
| tree | 61a8c19a66a55c31c775f4d8bc0b94bd081f82f1 | |
| parent | 52c0f5b39efd7c71e63a3a680a1d91f3efc8eda5 (diff) | |
Add press_enter_prompt
| -rw-r--r-- | src/main.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index 3e37ce2..15bcc8e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,6 +45,11 @@ fn clear_terminal(stdout: &mut StdoutLock) -> io::Result<()> { stdout.write_all(b"\x1b[H\x1b[2J\x1b[3J") } +fn press_enter_prompt() -> io::Result<()> { + io::stdin().lock().read_until(b'\n', &mut Vec::new())?; + Ok(()) +} + /// Rustlings is a collection of small exercises to get you used to writing and reading Rust code #[derive(Parser)] #[command(version)] @@ -98,7 +103,7 @@ fn main() -> Result<()> { let mut stdout = io::stdout().lock(); stdout.write_all(b"This command will create the directory `rustlings/` which will contain the exercises.\nPress ENTER to continue ")?; stdout.flush()?; - io::stdin().lock().read_until(b'\n', &mut Vec::new())?; + press_enter_prompt()?; stdout.write_all(b"\n")?; } @@ -134,9 +139,7 @@ fn main() -> Result<()> { let welcome_message = welcome_message.trim(); write!(stdout, "{welcome_message}\n\nPress ENTER to continue ")?; stdout.flush()?; - - io::stdin().lock().read_until(b'\n', &mut Vec::new())?; - + press_enter_prompt()?; clear_terminal(&mut stdout)?; } StateFileStatus::Read => (), |
