mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-26 23:36:30 +00:00
Add press_enter_prompt
This commit is contained in:
parent
52c0f5b39e
commit
2b7ac91505
1 changed files with 7 additions and 4 deletions
11
src/main.rs
11
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 => (),
|
||||
|
|
Loading…
Reference in a new issue