1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2024-09-07 20:02:17 +02:00

Add press_enter_prompt

This commit is contained in:
mo8it 2024-04-30 01:46:57 +02:00
parent 52c0f5b39e
commit 2b7ac91505

View File

@ -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 => (),