A small function I wanted to use in one of my other examples so I can "hold" the process while switching to another terminal to look at the memory
usage via htop
. I ended up using a crate to show the used and free memory from inside the example.
examples/press-enter-to-continue/src/main.rs
use std::io;
use std::io::Write;
fn main() {
println!("Before");
wait_for_enter().unwrap();
println!("After");
}
fn wait_for_enter() -> Result<(), std::io::Error> {
print!("Press ENTER to continue!");
std::io::stdout().flush()?;
let mut buffer = String::new();
let stdin = io::stdin();
stdin.read_line(&mut buffer)?;
Ok(())
}
See also the prompt as this is just a simple verion of it.