home ~ projects ~ socials

Read A Single Character From The Command Line In Rust

This is for a confirmation prompt using the dialoguer crate.

use dialoguer::Confirm;

pub fn main() {
    if Confirm::new()
        .with_prompt("Do you want to continue?")
        .interact()
        .unwrap()
    {
        println!("Looks like you want to continue");
    } else {
        println!("nevermind then :(");
    }
}

It took me a while to find this. The references below show some of the things I went through looking for the solution.

-- end of line --

References