1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
use dialoguer::theme::ColorfulTheme; use dialoguer::{Confirm, Input}; pub use yaga_derive::Dialogue; use std::io; pub trait Dialogue { fn compose(prompt: &str) -> io::Result<Self> where Self: Sized; } macro_rules! impl_dialogue { ($typ: ty) => { impl Dialogue for $typ { fn compose(prompt: &str) -> io::Result<Self> { Input::with_theme(&ColorfulTheme::default()) .with_prompt(prompt) .interact() } } }; } impl_dialogue!(String); impl_dialogue!(i8); impl_dialogue!(i16); impl_dialogue!(i32); impl_dialogue!(i64); impl_dialogue!(u8); impl_dialogue!(u16); impl_dialogue!(u32); impl_dialogue!(u64); impl_dialogue!(f32); impl_dialogue!(f64); impl_dialogue!(usize); impl_dialogue!(isize); impl Dialogue for bool { fn compose(prompt: &str) -> io::Result<Self> where Self: Sized, { Ok(Confirm::with_theme(&ColorfulTheme::default()) .with_prompt(prompt) .interact()?) } }