MCPcopy Create free account
hub / github.com/clawshell/clawshell / prompt_confirm_compact

Function prompt_confirm_compact

src/tui.rs:231–261  ·  view source on GitHub ↗
(message: &str, default: bool)

Source from the content-addressed store, hash-verified

229
230#[cfg_attr(test, allow(dead_code))]
231pub fn prompt_confirm_compact(message: &str, default: bool) -> Result<bool, Box<dyn Error>> {
232 let question_prefix = theme_style().apply_to("?");
233 let answer_prefix = success_style().apply_to("✓");
234 let warning_prefix = warning_style().apply_to("⚠");
235 let suffix = if default { "(Y/n)" } else { "(y/N)" };
236
237 loop {
238 print!("{question_prefix} {message} {suffix} ");
239 io::stdout().flush()?;
240
241 let mut input = String::new();
242 io::stdin().read_line(&mut input)?;
243 let trimmed = input.trim();
244
245 let decision = if trimmed.is_empty() {
246 Some(default)
247 } else {
248 parse_compact_confirm_input(trimmed)
249 };
250
251 if let Some(approved) = decision {
252 let answer = theme_style().apply_to(if approved { "Yes" } else { "No" });
253 // Move up to the prompt row, clear it, then print the finalized answer row.
254 print!("\x1b[1A\r\x1b[2K{answer_prefix} {message} {answer}\n");
255 io::stdout().flush()?;
256 return Ok(approved);
257 }
258
259 println!("{warning_prefix} Enter y/yes or n/no.");
260 }
261}
262
263pub fn prompt_select<T: Display>(message: &str, options: Vec<T>) -> Result<T, InquireError> {
264 Select::new(message, options)

Callers 1

run_openclaw_rawFunction · 0.85

Calls 5

theme_styleFunction · 0.85
success_styleFunction · 0.85
warning_styleFunction · 0.85
read_lineMethod · 0.80

Tested by

no test coverage detected