blob: 2f28aee2678e66f3f3d9f992b1c644224d0b14f1 (
plain)
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
|
use anyhow::{bail, Result};
use dialoguer::{theme::ColorfulTheme, Input};
#[cfg(test)]
use mockall::*;
#[derive(Default)]
pub struct Interactor {
theme: ColorfulTheme,
}
#[cfg_attr(test, automock)]
pub trait InteractorPrompt {
fn input(&self, parms: PromptInputParms) -> Result<String>;
}
impl InteractorPrompt for Interactor {
fn input(&self, parms: PromptInputParms) -> Result<String> {
let input: String = Input::with_theme(&self.theme)
.with_prompt(parms.prompt)
.interact_text()?;
Ok(input)
}
}
#[derive(Default)]
pub struct PromptInputParms {
pub prompt: String,
}
impl PromptInputParms {
pub fn with_prompt<S: Into<String>>(mut self, prompt: S) -> Self {
self.prompt = prompt.into();
self
}
}
|