Skip to main content

novel_api/common/utils/
input.rs

1use dialoguer::theme::ColorfulTheme;
2use dialoguer::{Confirm, Input, Password};
3
4use crate::Error;
5
6pub fn input<T>(prompt: T) -> Result<String, Error>
7where
8    T: AsRef<str>,
9{
10    Ok(Input::with_theme(&ColorfulTheme::default())
11        .with_prompt(prompt.as_ref())
12        .interact_text()?)
13}
14
15pub fn password<T>(prompt: T) -> Result<String, Error>
16where
17    T: AsRef<str>,
18{
19    Ok(Password::with_theme(&ColorfulTheme::default())
20        .with_prompt(prompt.as_ref())
21        .interact()?)
22}
23
24pub fn confirm<T>(prompt: T) -> Result<bool, Error>
25where
26    T: AsRef<str>,
27{
28    Ok(Confirm::with_theme(&ColorfulTheme::default())
29        .with_prompt(prompt.as_ref())
30        .interact()?)
31}