upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2023-11-01 00:00:00 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2023-11-01 00:00:00 +0000
commitd7d5576195149203f016677c3965d90fd2428fde (patch)
tree1e8b7a2fb41c2d13b5a8e818d668ad855bd42cff /src
parentda1ec6a6e63c3e710fffe35e2ee53d71cced8d28 (diff)
feat:(cli_interactor) add choice selector
add single choice selector as an enabler for selecting pr from a list
Diffstat (limited to 'src')
-rw-r--r--src/cli_interactor.rs26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/cli_interactor.rs b/src/cli_interactor.rs
index cf6e3d0..e52cefb 100644
--- a/src/cli_interactor.rs
+++ b/src/cli_interactor.rs
@@ -1,4 +1,4 @@
1use anyhow::Result; 1use anyhow::{Context, Result};
2use dialoguer::{theme::ColorfulTheme, Confirm, Input, Password}; 2use dialoguer::{theme::ColorfulTheme, Confirm, Input, Password};
3#[cfg(test)] 3#[cfg(test)]
4use mockall::*; 4use mockall::*;
@@ -13,6 +13,7 @@ pub trait InteractorPrompt {
13 fn input(&self, parms: PromptInputParms) -> Result<String>; 13 fn input(&self, parms: PromptInputParms) -> Result<String>;
14 fn password(&self, parms: PromptPasswordParms) -> Result<String>; 14 fn password(&self, parms: PromptPasswordParms) -> Result<String>;
15 fn confirm(&self, params: PromptConfirmParms) -> Result<bool>; 15 fn confirm(&self, params: PromptConfirmParms) -> Result<bool>;
16 fn choice(&self, params: PromptChoiceParms) -> Result<usize>;
16} 17}
17impl InteractorPrompt for Interactor { 18impl InteractorPrompt for Interactor {
18 fn input(&self, parms: PromptInputParms) -> Result<String> { 19 fn input(&self, parms: PromptInputParms) -> Result<String> {
@@ -37,6 +38,12 @@ impl InteractorPrompt for Interactor {
37 .interact()?; 38 .interact()?;
38 Ok(confirm) 39 Ok(confirm)
39 } 40 }
41 fn choice(&self, parms: PromptChoiceParms) -> Result<usize> {
42 dialoguer::Select::with_theme(&self.theme)
43 .items(&parms.choices)
44 .interact()
45 .context("failed to get choice")
46 }
40} 47}
41 48
42#[derive(Default)] 49#[derive(Default)]
@@ -84,3 +91,20 @@ impl PromptConfirmParms {
84 self 91 self
85 } 92 }
86} 93}
94
95#[derive(Default)]
96pub struct PromptChoiceParms {
97 pub prompt: String,
98 pub choices: Vec<String>,
99}
100
101impl PromptChoiceParms {
102 pub fn with_prompt<S: Into<String>>(mut self, prompt: S) -> Self {
103 self.prompt = prompt.into();
104 self
105 }
106 pub fn with_choices(mut self, choices: Vec<String>) -> Self {
107 self.choices = choices;
108 self
109 }
110}