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.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/cli_interactor.rs b/src/cli_interactor.rs
index a702a54..dc15c87 100644
--- a/src/cli_interactor.rs
+++ b/src/cli_interactor.rs
@@ -41,12 +41,17 @@ impl InteractorPrompt for Interactor {
41 Ok(confirm) 41 Ok(confirm)
42 } 42 }
43 fn choice(&self, parms: PromptChoiceParms) -> Result<usize> { 43 fn choice(&self, parms: PromptChoiceParms) -> Result<usize> {
44 dialoguer::Select::with_theme(&self.theme) 44 let mut choice = dialoguer::Select::with_theme(&self.theme);
45 choice
45 .with_prompt(parms.prompt) 46 .with_prompt(parms.prompt)
46 .report(parms.report) 47 .report(parms.report)
47 .items(&parms.choices) 48 .items(&parms.choices);
48 .interact() 49 if let Some(default) = parms.default {
49 .context("failed to get choice") 50 if std::env::var("NGITTEST").is_err() {
51 choice.default(default);
52 }
53 }
54 choice.interact().context("failed to get choice")
50 } 55 }
51} 56}
52 57
@@ -110,6 +115,7 @@ impl PromptConfirmParms {
110pub struct PromptChoiceParms { 115pub struct PromptChoiceParms {
111 pub prompt: String, 116 pub prompt: String,
112 pub choices: Vec<String>, 117 pub choices: Vec<String>,
118 pub default: Option<usize>,
113 pub report: bool, 119 pub report: bool,
114} 120}
115 121
@@ -128,4 +134,9 @@ impl PromptChoiceParms {
128 self.choices = choices; 134 self.choices = choices;
129 self 135 self
130 } 136 }
137
138 pub fn with_default(mut self, index: usize) -> Self {
139 self.default = Some(index);
140 self
141 }
131} 142}