Skip to content

Commit b1ee13d

Browse files
committed
refactor: address PR review feedback for show_hint
1 parent d15e985 commit b1ee13d

5 files changed

Lines changed: 34 additions & 56 deletions

File tree

examples/no_hint.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/prompts/confirm.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,12 @@ impl Confirm<'_> {
172172
None
173173
};
174174

175-
render.confirm_prompt(&self.prompt, default_if_show, self.show_hint)?;
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+
}
176181

177182
term.hide_cursor()?;
178183
term.flush()?;
@@ -214,7 +219,7 @@ impl Confirm<'_> {
214219
};
215220

216221
term.clear_line()?;
217-
render.confirm_prompt(&self.prompt, value, self.show_hint)?;
222+
render.confirm_prompt(&self.prompt, value)?;
218223
}
219224
} else {
220225
// Default behavior: matches continuously on every keystroke,

src/theme/colorful.rs

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ impl Theme for ColorfulTheme {
139139
f: &mut dyn fmt::Write,
140140
prompt: &str,
141141
default: Option<bool>,
142-
show_hint: bool,
143142
) -> fmt::Result {
144143
if !prompt.is_empty() {
145144
write!(
@@ -150,31 +149,27 @@ impl Theme for ColorfulTheme {
150149
)?;
151150
}
152151

153-
if show_hint {
154-
match default {
155-
None => write!(
156-
f,
157-
"{} {}",
158-
self.hint_style.apply_to("(y/n)"),
159-
&self.prompt_suffix
160-
),
161-
Some(true) => write!(
162-
f,
163-
"{} {} {}",
164-
self.hint_style.apply_to("(y/n)"),
165-
&self.prompt_suffix,
166-
self.defaults_style.apply_to("yes")
167-
),
168-
Some(false) => write!(
169-
f,
170-
"{} {} {}",
171-
self.hint_style.apply_to("(y/n)"),
172-
&self.prompt_suffix,
173-
self.defaults_style.apply_to("no")
174-
),
175-
}
176-
} else {
177-
Ok(())
152+
match default {
153+
None => write!(
154+
f,
155+
"{} {}",
156+
self.hint_style.apply_to("(y/n)"),
157+
&self.prompt_suffix
158+
),
159+
Some(true) => write!(
160+
f,
161+
"{} {} {}",
162+
self.hint_style.apply_to("(y/n)"),
163+
&self.prompt_suffix,
164+
self.defaults_style.apply_to("yes")
165+
),
166+
Some(false) => write!(
167+
f,
168+
"{} {} {}",
169+
self.hint_style.apply_to("(y/n)"),
170+
&self.prompt_suffix,
171+
self.defaults_style.apply_to("no")
172+
),
178173
}
179174
}
180175
/// Formats a confirm prompt after selection.

src/theme/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,14 @@ pub trait Theme {
3333
f: &mut dyn fmt::Write,
3434
prompt: &str,
3535
default: Option<bool>,
36-
show_hint: bool,
3736
) -> fmt::Result {
3837
if !prompt.is_empty() {
3938
write!(f, "{} ", &prompt)?;
4039
}
41-
if show_hint {
42-
match default {
43-
None => write!(f, "[y/n] ")?,
44-
Some(true) => write!(f, "[Y/n] ")?,
45-
Some(false) => write!(f, "[y/N] ")?,
46-
}
40+
match default {
41+
None => write!(f, "[y/n] ")?,
42+
Some(true) => write!(f, "[Y/n] ")?,
43+
Some(false) => write!(f, "[y/N] ")?,
4744
}
4845
Ok(())
4946
}

src/theme/render.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,8 @@ impl<'a> TermThemeRenderer<'a> {
8787
self.write_formatted_line(|this, buf| this.theme.format_error(buf, err))
8888
}
8989

90-
pub fn confirm_prompt(
91-
&mut self,
92-
prompt: &str,
93-
default: Option<bool>,
94-
show_hint: bool,
95-
) -> Result<usize> {
96-
self.write_formatted_str(|this, buf| {
97-
this.theme
98-
.format_confirm_prompt(buf, prompt, default, show_hint)
99-
})
90+
pub fn confirm_prompt(&mut self, prompt: &str, default: Option<bool>) -> Result<usize> {
91+
self.write_formatted_str(|this, buf| this.theme.format_confirm_prompt(buf, prompt, default))
10092
}
10193

10294
pub fn confirm_prompt_selection(&mut self, prompt: &str, sel: Option<bool>) -> Result {

0 commit comments

Comments
 (0)