From 4bab679f3559fb11f3d1acf92eb490a977812c82 Mon Sep 17 00:00:00 2001 From: opmr0 <265859855+opmr0@users.noreply.github.com> Date: Tue, 7 Apr 2026 13:59:32 +0300 Subject: [PATCH 1/3] feat: add show_hint option to Confirm prompt --- src/prompts/confirm.rs | 17 ++++++++++++++++- src/theme/colorful.rs | 1 - 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/prompts/confirm.rs b/src/prompts/confirm.rs index 8ff126f..e1404cb 100644 --- a/src/prompts/confirm.rs +++ b/src/prompts/confirm.rs @@ -35,6 +35,7 @@ pub struct Confirm<'a> { show_default: bool, wait_for_newline: bool, theme: &'a dyn Theme, + show_hint: bool, } impl Default for Confirm<'static> { @@ -97,6 +98,14 @@ impl Confirm<'_> { self } + /// Disables or enables the hint display (e.g. `[y/n]`). + /// + /// The default is to show the hint. + pub fn show_hint(mut self, val: bool) -> Self { + self.show_hint = val; + self + } + /// Enables user interaction and returns the result. /// /// The dialog is rendered on stderr. @@ -163,7 +172,12 @@ impl Confirm<'_> { None }; - render.confirm_prompt(&self.prompt, default_if_show)?; + term.clear_line()?; + if self.show_hint { + render.confirm_prompt(&self.prompt, default_if_show)?; + } else { + term.write_str(&format!("{} ", &self.prompt))?; + } term.hide_cursor()?; term.flush()?; @@ -260,6 +274,7 @@ impl<'a> Confirm<'a> { show_default: true, wait_for_newline: false, theme, + show_hint: true, } } } diff --git a/src/theme/colorful.rs b/src/theme/colorful.rs index 787ab7f..1b3b5aa 100644 --- a/src/theme/colorful.rs +++ b/src/theme/colorful.rs @@ -172,7 +172,6 @@ impl Theme for ColorfulTheme { ), } } - /// Formats a confirm prompt after selection. fn format_confirm_prompt_selection( &self, From 7199b9c86d34cd7a369d994af9a2a735ecfc1d70 Mon Sep 17 00:00:00 2001 From: opmr0 <265859855+opmr0@users.noreply.github.com> Date: Tue, 7 Apr 2026 15:08:11 +0300 Subject: [PATCH 2/3] add: format_confirm_prompt_no_hint --- src/prompts/confirm.rs | 3 +-- src/theme/colorful.rs | 15 +++++++++++++++ src/theme/mod.rs | 8 ++++++++ src/theme/render.rs | 4 ++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/prompts/confirm.rs b/src/prompts/confirm.rs index e1404cb..c3978b9 100644 --- a/src/prompts/confirm.rs +++ b/src/prompts/confirm.rs @@ -172,11 +172,10 @@ impl Confirm<'_> { None }; - term.clear_line()?; if self.show_hint { render.confirm_prompt(&self.prompt, default_if_show)?; } else { - term.write_str(&format!("{} ", &self.prompt))?; + render.confirm_prompt_no_hint(&self.prompt)?; } term.hide_cursor()?; diff --git a/src/theme/colorful.rs b/src/theme/colorful.rs index 1b3b5aa..545a5fd 100644 --- a/src/theme/colorful.rs +++ b/src/theme/colorful.rs @@ -172,6 +172,21 @@ impl Theme for ColorfulTheme { ), } } + + /// Formats an input prompt without a hint. + fn format_confirm_prompt_no_hint(&self, f: &mut dyn fmt::Write, prompt: &str) -> fmt::Result { + if !prompt.is_empty() { + write!( + f, + "{} {} {}", + &self.prompt_prefix, + self.prompt_style.apply_to(prompt), + &self.prompt_suffix + )?; + } + Ok(()) + } + /// Formats a confirm prompt after selection. fn format_confirm_prompt_selection( &self, diff --git a/src/theme/mod.rs b/src/theme/mod.rs index d22001c..01d69c2 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -45,6 +45,14 @@ pub trait Theme { Ok(()) } + /// Formats a confirm prompt without a hint. + fn format_confirm_prompt_no_hint(&self, f: &mut dyn fmt::Write, prompt: &str) -> fmt::Result { + if !prompt.is_empty() { + write!(f, "{} ", prompt)?; + } + Ok(()) + } + /// Formats a confirm prompt after selection. fn format_confirm_prompt_selection( &self, diff --git a/src/theme/render.rs b/src/theme/render.rs index e6f3add..53ed833 100644 --- a/src/theme/render.rs +++ b/src/theme/render.rs @@ -91,6 +91,10 @@ impl<'a> TermThemeRenderer<'a> { self.write_formatted_str(|this, buf| this.theme.format_confirm_prompt(buf, prompt, default)) } + pub fn confirm_prompt_no_hint(&mut self, prompt: &str) -> Result { + self.write_formatted_str(|this, buf| this.theme.format_confirm_prompt_no_hint(buf, prompt)) + } + pub fn confirm_prompt_selection(&mut self, prompt: &str, sel: Option) -> Result { self.write_formatted_prompt(|this, buf| { this.theme.format_confirm_prompt_selection(buf, prompt, sel) From 9e70e9e3d419dbc1a033497139df7bb0a737fc25 Mon Sep 17 00:00:00 2001 From: opmr0 <265859855+opmr0@users.noreply.github.com> Date: Tue, 7 Apr 2026 15:23:18 +0300 Subject: [PATCH 3/3] fix: format_confirm_prompt_no_hint function comment --- src/theme/colorful.rs | 2 +- src/theme/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/theme/colorful.rs b/src/theme/colorful.rs index 545a5fd..28ad8e9 100644 --- a/src/theme/colorful.rs +++ b/src/theme/colorful.rs @@ -173,7 +173,7 @@ impl Theme for ColorfulTheme { } } - /// Formats an input prompt without a hint. + /// Formats a confirm prompt without the hint ([y/n]). fn format_confirm_prompt_no_hint(&self, f: &mut dyn fmt::Write, prompt: &str) -> fmt::Result { if !prompt.is_empty() { write!( diff --git a/src/theme/mod.rs b/src/theme/mod.rs index 01d69c2..2470364 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -45,7 +45,7 @@ pub trait Theme { Ok(()) } - /// Formats a confirm prompt without a hint. + /// Formats a confirm prompt without the hint ([y/n]). fn format_confirm_prompt_no_hint(&self, f: &mut dyn fmt::Write, prompt: &str) -> fmt::Result { if !prompt.is_empty() { write!(f, "{} ", prompt)?;