pub struct Prompt<T: Renderer> {
pub renderer: T,
}Expand description
Represents a customizable prompt that can handle user input and produce a result.
This struct encapsulates the rendering logic, event handling, and result production for a prompt.
Fields§
§renderer: TImplementations§
source§impl<T: Renderer> Prompt<T>
impl<T: Renderer> Prompt<T>
sourcepub fn run(&mut self) -> Result<T::Return>
pub fn run(&mut self) -> Result<T::Return>
Runs the prompt, handling events and producing a result.
This method initializes the terminal, and enters a loop to handle events until a quit signal is received. After exiting the loop, it produces and returns the result.
§Returns
Returns a Result containing the produced result or an error.
Examples found in repository?
More examples
examples/checkbox.rs (line 19)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
fn main() -> anyhow::Result<()> {
let mut p = Checkbox::new(vec![
"Apple",
"Banana",
"Orange",
"Mango",
"Strawberry",
"Pineapple",
"Grape",
"Watermelon",
"Kiwi",
"Pear",
])
.title("What are your favorite fruits?")
.checkbox_lines(5)
.prompt()?;
println!("result: {:?}", p.run()?);
Ok(())
}examples/readline.rs (line 17)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
fn main() -> anyhow::Result<()> {
let mut p = Readline::default()
.title("Hi!")
.enable_suggest(Suggest::from_iter([
"apple",
"applet",
"application",
"banana",
]))
.validator(
|text| text.len() > 10,
|text| format!("Length must be over 10 but got {}", text.len()),
)
.prompt()?;
println!("result: {:?}", p.run()?);
Ok(())
}Additional examples can be found in:
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Prompt<T>where
T: Freeze,
impl<T> RefUnwindSafe for Prompt<T>where
T: RefUnwindSafe,
impl<T> Send for Prompt<T>where
T: Send,
impl<T> Sync for Prompt<T>where
T: Sync,
impl<T> Unpin for Prompt<T>where
T: Unpin,
impl<T> UnwindSafe for Prompt<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more