use std::io::Write;
use crossterm::style::Stylize;
pub fn ask_permission(tool_name: &str, description: &str) -> bool {
eprintln!();
eprintln!(
"{} {} wants to execute:",
" PERMISSION ".on_yellow().black().bold(),
tool_name.bold(),
);
eprintln!(" {}", description.dark_grey());
eprint!(" Allow? [y/N] ");
let _ = std::io::stderr().flush();
let mut input = String::new();
match std::io::stdin().read_line(&mut input) {
Ok(_) => {
let answer = input.trim().to_lowercase();
matches!(answer.as_str(), "y" | "yes")
}
Err(_) => false,
}
}
pub fn print_colored_diff(diff: &str) {
for line in diff.lines() {
if line.starts_with('+') && !line.starts_with("+++") {
println!("{}", line.green());
} else if line.starts_with('-') && !line.starts_with("---") {
println!("{}", line.red());
} else if line.starts_with("@@") {
println!("{}", line.cyan());
} else if line.starts_with("diff ") {
println!("{}", line.bold());
} else {
println!("{line}");
}
}
}
pub fn print_edit_summary(file_path: &str, old: &str, new: &str) {
println!("{}", format!(" {file_path}:").bold());
for line in old.lines().take(3) {
println!(" {}", format!("- {line}").red());
}
for line in new.lines().take(3) {
println!(" {}", format!("+ {line}").green());
}
if old.lines().count() > 3 || new.lines().count() > 3 {
println!(" {}", "...".dark_grey());
}
}