use colored::*;
use std::io::{self, Write};
use std::thread;
use std::time::{Duration, Instant};
pub enum Status {
Ok,
Error,
Info,
}
pub fn clear_screen() {
print!("\x1B[2J\x1B[1;1H");
let _ = io::stdout().flush();
}
pub fn log_status(message: &str, status: Status) {
let status_colored = match status {
Status::Ok => "SUCCESS".green().bold(),
Status::Error => "ERROR".red().bold(),
Status::Info => "INFO".blue().bold(),
};
println!("[{}] {}", status_colored, message);
}
pub fn show_progress(current: u32, total: u32) {
if total == 0 {
print!("\rProgreso: [0.0%]");
let _ = io::stdout().flush();
return;
}
let percentage = (current as f32 / total as f32) * 100.0;
print!("\rProgreso: [{:.1}%] ", percentage);
let _ = io::stdout().flush();
}
pub fn typewriter_print(text: &str, speed_ms: u64) {
for c in text.chars() {
print!("{}", format!("{}", c).cyan());
let _ = io::stdout().flush();
thread::sleep(Duration::from_millis(speed_ms));
}
println!();
}
pub fn print_banner(title: &str) {
println!("{}", "=".repeat(40).yellow());
println!("{:^40}", title.bright_magenta().bold());
println!("{}", "=".repeat(40).yellow());
}
pub fn get_input(prompt: &str) -> String {
print!("{} ", prompt.bright_white().italic());
let _ = io::stdout().flush();
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("Error al leer entrada");
input.trim().to_string()
}
pub fn show_spinner(message: &str, duration_secs: u64) {
let symbols = ["|", "/", "-", "\\"];
let start = Instant::now();
let mut i = 0;
while start.elapsed().as_secs() < duration_secs {
print!("\r{} {}", symbols[i % 4].bright_cyan(), message);
let _ = io::stdout().flush();
thread::sleep(Duration::from_millis(100));
i += 1;
}
println!("\r{} {} ", "✔".green(), message);
}