keyfork/crates/util/keyfork-prompt/examples/test-basic-prompt.rs

37 lines
778 B
Rust

//!
use std::io::{stdin, stdout};
use keyfork_prompt::{
MaybeIdentifier, PromptHandler, Terminal,
};
#[derive(PartialEq, Eq, Debug)]
pub enum Example {
RetryQR,
UseMnemonic,
}
impl MaybeIdentifier for Example {}
impl std::fmt::Display for Example {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Example::RetryQR => f.write_str("Retry QR Code"),
Example::UseMnemonic => f.write_str("Use Mnemonic"),
}
}
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut mgr = Terminal::new(stdin(), stdout())?;
let choice = mgr.prompt_choice(
"Unable to detect QR code.",
&[Example::RetryQR, Example::UseMnemonic],
)?;
dbg!(choice);
Ok(())
}