use crate::commands::script::{Scripts, Script};
use colored::*;
pub fn show_scripts(scripts: &Scripts) {
let mut max_script_name_len = "Script".len();
let mut max_description_len = "Description".len();
for (name, script) in &scripts.scripts {
max_script_name_len = max_script_name_len.max(name.len() + 2);
let description = match script {
Script::Default(_) => "",
Script::Inline { info, .. } | Script::CILike { info, .. } => info.as_deref().unwrap_or(""),
};
max_description_len = max_description_len.max(description.len() + 2);
}
println!("{:<width1$} {:<width2$}", "Script".yellow(), "Description".yellow(), width1 = max_script_name_len, width2 = max_description_len);
println!("{:<width1$} {:<width2$}", "-".repeat(max_script_name_len).yellow(), "-".repeat(max_description_len).yellow(), width1 = max_script_name_len, width2 = max_description_len);
for (name, script) in &scripts.scripts {
let description = match script {
Script::Default(_) => "".to_string(),
Script::Inline { info, .. } | Script::CILike { info, .. } => info.clone().unwrap_or_else(|| "".to_string()),
};
println!("{:<width1$} {:<width2$}", name.green(), description, width1 = max_script_name_len, width2 = max_description_len);
}
}