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:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-03-08 14:37:56 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-03-08 14:39:21 +0000
commit6b3aecbcbde669859533716225e9c3bbfd2023b2 (patch)
tree06258c93893c57ae1ef3b3d709c364f00365fdb5 /src/cli_interactor.rs
parent5622e384447fba354548aca0e39dcee3d95951c3 (diff)
feat(send): select commits from a list
when since_or_range isn't specified adds resilience as assuming master..HEAD can cause some issues eg when master is not up-to-date with origin/master
Diffstat (limited to 'src/cli_interactor.rs')
-rw-r--r--src/cli_interactor.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/cli_interactor.rs b/src/cli_interactor.rs
index dc15c87..4cf6357 100644
--- a/src/cli_interactor.rs
+++ b/src/cli_interactor.rs
@@ -14,6 +14,7 @@ pub trait InteractorPrompt {
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 fn choice(&self, params: PromptChoiceParms) -> Result<usize>;
17 fn multi_choice(&self, params: PromptMultiChoiceParms) -> Result<Vec<usize>>;
17} 18}
18impl InteractorPrompt for Interactor { 19impl InteractorPrompt for Interactor {
19 fn input(&self, parms: PromptInputParms) -> Result<String> { 20 fn input(&self, parms: PromptInputParms) -> Result<String> {
@@ -53,6 +54,18 @@ impl InteractorPrompt for Interactor {
53 } 54 }
54 choice.interact().context("failed to get choice") 55 choice.interact().context("failed to get choice")
55 } 56 }
57 fn multi_choice(&self, parms: PromptMultiChoiceParms) -> Result<Vec<usize>> {
58 // the colorful theme is not very clear so falling back to default
59 let mut choice = dialoguer::MultiSelect::default();
60 choice
61 .with_prompt(parms.prompt)
62 .report(parms.report)
63 .items(&parms.choices);
64 if let Some(defaults) = parms.defaults {
65 choice.defaults(&defaults);
66 }
67 choice.interact().context("failed to get choice")
68 }
56} 69}
57 70
58#[derive(Default)] 71#[derive(Default)]
@@ -140,3 +153,34 @@ impl PromptChoiceParms {
140 self 153 self
141 } 154 }
142} 155}
156
157#[derive(Default)]
158pub struct PromptMultiChoiceParms {
159 pub prompt: String,
160 pub choices: Vec<String>,
161 pub defaults: Option<Vec<bool>>,
162 pub report: bool,
163}
164
165impl PromptMultiChoiceParms {
166 pub fn with_prompt<S: Into<String>>(mut self, prompt: S) -> Self {
167 self.prompt = prompt.into();
168 self.report = true;
169 self
170 }
171
172 pub fn dont_report(mut self) -> Self {
173 self.report = false;
174 self
175 }
176
177 pub fn with_choices(mut self, choices: Vec<String>) -> Self {
178 self.choices = choices;
179 self
180 }
181
182 pub fn with_defaults(mut self, defaults: Vec<bool>) -> Self {
183 self.defaults = Some(defaults);
184 self
185 }
186}