"Press any key to exit..." in Rust

⚓ Rust    📅 2025-11-08    👤 surdeus    👁️ 7      

surdeus

I made this code that works that when you press any key it exits the program. add "console = "0.16.1"" to your cargo.toml file then use this code.


use console::Term;
use std::io;
println!("Press any key to exit...");
let stdout: Term = Term::buffered_stdout();
loop {
            let z: Result<char, io::Error> = stdout.read_char();
            let wow: char = "".chars().next().unwrap_or_default();
            if z.unwrap() != wow {
                return;
            }
        }

3 posts - 2 participants

Read full topic

🏷️ Rust_feed