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

37 lines
778 B
Rust
Raw Permalink Normal View History

2024-01-16 02:44:48 +00:00
//!
use std::io::{stdin, stdout};
use keyfork_prompt::{
2024-08-01 11:16:05 +00:00
MaybeIdentifier, PromptHandler, Terminal,
};
2024-08-01 11:16:05 +00:00
#[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"),
}
}
}
2024-01-07 04:23:41 +00:00
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut mgr = Terminal::new(stdin(), stdout())?;
2024-08-01 11:16:05 +00:00
let choice = mgr.prompt_choice(
"Unable to detect QR code.",
&[Example::RetryQR, Example::UseMnemonic],
)?;
2024-08-01 11:16:05 +00:00
dbg!(choice);
Ok(())
}