(message: &str, default: bool)
| 229 | |
| 230 | #[cfg_attr(test, allow(dead_code))] |
| 231 | pub 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 | |
| 263 | pub fn prompt_select<T: Display>(message: &str, options: Vec<T>) -> Result<T, InquireError> { |
| 264 | Select::new(message, options) |
no test coverage detected