Skip to content

Commit 4bab679

Browse files
committed
feat: add show_hint option to Confirm prompt
1 parent 5446de0 commit 4bab679

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/prompts/confirm.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub struct Confirm<'a> {
3535
show_default: bool,
3636
wait_for_newline: bool,
3737
theme: &'a dyn Theme,
38+
show_hint: bool,
3839
}
3940

4041
impl Default for Confirm<'static> {
@@ -97,6 +98,14 @@ impl Confirm<'_> {
9798
self
9899
}
99100

101+
/// Disables or enables the hint display (e.g. `[y/n]`).
102+
///
103+
/// The default is to show the hint.
104+
pub fn show_hint(mut self, val: bool) -> Self {
105+
self.show_hint = val;
106+
self
107+
}
108+
100109
/// Enables user interaction and returns the result.
101110
///
102111
/// The dialog is rendered on stderr.
@@ -163,7 +172,12 @@ impl Confirm<'_> {
163172
None
164173
};
165174

166-
render.confirm_prompt(&self.prompt, default_if_show)?;
175+
term.clear_line()?;
176+
if self.show_hint {
177+
render.confirm_prompt(&self.prompt, default_if_show)?;
178+
} else {
179+
term.write_str(&format!("{} ", &self.prompt))?;
180+
}
167181

168182
term.hide_cursor()?;
169183
term.flush()?;
@@ -260,6 +274,7 @@ impl<'a> Confirm<'a> {
260274
show_default: true,
261275
wait_for_newline: false,
262276
theme,
277+
show_hint: true,
263278
}
264279
}
265280
}

src/theme/colorful.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ impl Theme for ColorfulTheme {
172172
),
173173
}
174174
}
175-
176175
/// Formats a confirm prompt after selection.
177176
fn format_confirm_prompt_selection(
178177
&self,

0 commit comments

Comments
 (0)