upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/cli_interactor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli_interactor.rs')
-rw-r--r--src/cli_interactor.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/cli_interactor.rs b/src/cli_interactor.rs
new file mode 100644
index 0000000..2f28aee
--- /dev/null
+++ b/src/cli_interactor.rs
@@ -0,0 +1,34 @@
1use anyhow::{bail, Result};
2use dialoguer::{theme::ColorfulTheme, Input};
3#[cfg(test)]
4use mockall::*;
5
6#[derive(Default)]
7pub struct Interactor {
8 theme: ColorfulTheme,
9}
10
11#[cfg_attr(test, automock)]
12pub trait InteractorPrompt {
13 fn input(&self, parms: PromptInputParms) -> Result<String>;
14}
15impl InteractorPrompt for Interactor {
16 fn input(&self, parms: PromptInputParms) -> Result<String> {
17 let input: String = Input::with_theme(&self.theme)
18 .with_prompt(parms.prompt)
19 .interact_text()?;
20 Ok(input)
21 }
22}
23
24#[derive(Default)]
25pub struct PromptInputParms {
26 pub prompt: String,
27}
28
29impl PromptInputParms {
30 pub fn with_prompt<S: Into<String>>(mut self, prompt: S) -> Self {
31 self.prompt = prompt.into();
32 self
33 }
34}