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

48 lines
1.1 KiB
Rust
Raw Normal View History

2024-08-11 23:25:25 +00:00
#![allow(missing_docs)]
2024-01-16 02:44:48 +00:00
use keyfork_prompt::default_handler;
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum Choices {
Retry,
Continue,
}
impl std::fmt::Display for Choices {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Choices::Retry => write!(
f,
"Retry with some really long text that I want to cause issues with."
),
Choices::Continue => write!(
f,
"Continue with some really long text that I want to cause issues with."
),
}
}
}
impl keyfork_prompt::Choice for Choices {
fn identifier(&self) -> Option<char> {
Some(match self {
Choices::Retry => 'r',
Choices::Continue => 'c',
})
}
}
2024-01-07 04:23:41 +00:00
fn main() -> Result<(), Box<dyn std::error::Error>> {
2025-01-30 17:10:36 +00:00
let mut handler = default_handler()?;
let choice = keyfork_prompt::prompt_choice(
&mut *handler,
"Here are some options!",
&[Choices::Retry, Choices::Continue],
);
dbg!(&choice);
Ok(())
}