use std::fmt::Display;
use std::path::Path;
use indicatif::{ProgressBar, ProgressStyle};
use owo_colors::OwoColorize;
pub const CHECK: &str = "✓";
pub const BULLET: &str = "•";
pub const PROGRESS_MIN_FILES: usize = 20;
pub fn accent(value: impl Display) -> String {
value.cyan().to_string()
}
pub fn path(value: &Path) -> String {
value.display().to_string().cyan().to_string()
}
pub fn success(value: impl Display) -> String {
value.green().to_string()
}
pub fn warn(value: impl Display) -> String {
value.yellow().to_string()
}
pub fn danger(value: impl Display) -> String {
value.red().to_string()
}
pub fn dim(value: impl Display) -> String {
value.dimmed().to_string()
}
pub fn bold(value: impl Display) -> String {
value.bold().to_string()
}
pub fn clap_styles() -> clap::builder::Styles {
use clap::builder::styling::{AnsiColor, Style};
clap::builder::Styles::styled()
.header(Style::new().bold().fg_color(Some(AnsiColor::Cyan.into())))
.usage(Style::new().bold().fg_color(Some(AnsiColor::Cyan.into())))
.literal(Style::new().bold().fg_color(Some(AnsiColor::Green.into())))
.placeholder(Style::new().fg_color(Some(AnsiColor::BrightBlack.into())))
.valid(Style::new().fg_color(Some(AnsiColor::Green.into())))
.invalid(Style::new().bold().fg_color(Some(AnsiColor::Red.into())))
.error(Style::new().bold().fg_color(Some(AnsiColor::Red.into())))
}
pub fn progress_bar(len: u64) -> ProgressBar {
use std::io::IsTerminal;
if !std::io::stderr().is_terminal() {
return ProgressBar::hidden();
}
let bar = ProgressBar::new(len);
let style = ProgressStyle::with_template(" {spinner:.cyan} [{bar:28.cyan/dim}] {pos}/{len} files {msg}")
.unwrap_or_else(|_| ProgressStyle::default_bar())
.progress_chars("━━╌");
bar.set_style(style);
bar
}
pub fn print_summary(total_files: usize, modified_files: usize, comments_removed: usize, dry_run: bool) {
let prefix = if dry_run { "[DRY RUN] " } else { "" };
let modified_verb = if dry_run { "would be modified" } else { "modified" };
anstream::println!();
anstream::println!(
"{}{} {} files processed, {} {}, {} comments removed",
dim(prefix),
bold("Summary:"),
accent(total_files),
accent(modified_files),
modified_verb,
accent(comments_removed),
);
if total_files > 0 && modified_files == 0 {
anstream::println!(
"{}",
dim("All files were already comment-free or only contained preserved comments.")
);
}
}