#![allow(dead_code)]
use owo_colors::OwoColorize;
use std::fmt::Display;
use std::path::Path;
fn use_colors() -> bool {
if std::env::var("NO_COLOR").is_ok() {
return false;
}
supports_color::on(supports_color::Stream::Stderr).is_some()
}
pub fn stdout_supports_color() -> bool {
if std::env::var("NO_COLOR").is_ok() {
return false;
}
supports_color::on(supports_color::Stream::Stdout).is_some()
}
pub fn success(msg: impl Display) {
if use_colors() {
eprintln!("{} {}", "✓".green(), msg);
} else {
eprintln!("✓ {}", msg);
}
}
pub fn info(msg: impl Display) {
eprintln!("{}", msg);
}
pub fn hint(msg: impl Display) {
if use_colors() {
eprintln!("{} {}", "hint:".dimmed(), msg.to_string().dimmed());
} else {
eprintln!("hint: {}", msg);
}
}
pub fn created(kind: &str, path: &Path) {
if use_colors() {
eprintln!("{} {}: {}", "Created".green(), kind, path.display().cyan());
} else {
eprintln!("Created {}: {}", kind, path.display());
}
}
#[allow(dead_code)]
pub fn path_str(p: &Path) -> String {
if use_colors() {
format!("{}", p.display().cyan())
} else {
format!("{}", p.display())
}
}
#[allow(dead_code)]
pub fn id_str(id: &str) -> String {
if use_colors() {
format!("{}", id.cyan().bold())
} else {
id.to_string()
}
}
pub fn field_set(id: &str, field: &str, value: &str) {
if use_colors() {
eprintln!(
"Set {}.{} = {}",
id.cyan().bold(),
field.yellow(),
value.white()
);
} else {
eprintln!("Set {}.{} = {}", id, field, value);
}
}
pub fn field_added(id: &str, field: &str, value: &str) {
if use_colors() {
eprintln!(
"Added '{}' to {}.{}",
value.white(),
id.cyan().bold(),
field.yellow()
);
} else {
eprintln!("Added '{}' to {}.{}", value, id, field);
}
}
pub fn field_removed(id: &str, field: &str, value: &str) {
if use_colors() {
eprintln!(
"Removed '{}' from {}.{}",
value.white(),
id.cyan().bold(),
field.yellow()
);
} else {
eprintln!("Removed '{}' from {}.{}", value, id, field);
}
}
pub fn moved(filename: &str, status: &str) {
if use_colors() {
eprintln!("Moved {} to {}", filename.cyan(), status.green().bold());
} else {
eprintln!("Moved {} to {}", filename, status);
}
}
pub fn transitioned(id: &str, action: &str, target: &str) {
if use_colors() {
eprintln!("{} {}: {}", action, id.cyan().bold(), target.green());
} else {
eprintln!("{} {}: {}", action, id, target);
}
}
pub fn phase_advanced(id: &str, phase: &str) {
if use_colors() {
eprintln!("Advanced {} to phase: {}", id.cyan().bold(), phase.green());
} else {
eprintln!("Advanced {} to phase: {}", id, phase);
}
}
pub fn version_bumped(id: &str, version: &str) {
if use_colors() {
eprintln!("Bumped {} to {}", id.cyan().bold(), version.green().bold());
} else {
eprintln!("Bumped {} to {}", id, version);
}
}
pub fn changelog_change_added(id: &str, version: &str, change: &str) {
if use_colors() {
eprintln!(
"Added change to {} v{}: {}",
id.cyan().bold(),
version.green(),
change
);
} else {
eprintln!("Added change to {} v{}: {}", id, version, change);
}
}
pub fn ticked(item: &str, status: &str) {
if use_colors() {
eprintln!("Marked '{}' as {}", item.white(), status.green());
} else {
eprintln!("Marked '{}' as {}", item, status);
}
}
pub fn accepted(kind: &str, id: &str) {
if use_colors() {
eprintln!("Accepted {}: {}", kind, id.cyan().bold());
} else {
eprintln!("Accepted {}: {}", kind, id);
}
}
pub fn rejected(kind: &str, id: &str) {
if use_colors() {
eprintln!("Rejected {}: {}", kind, id.cyan().bold());
} else {
eprintln!("Rejected {}: {}", kind, id);
}
}
pub fn deprecated(kind: &str, id: &str) {
if use_colors() {
eprintln!("Deprecated {}: {}", kind, id.yellow().bold());
} else {
eprintln!("Deprecated {}: {}", kind, id);
}
}
pub fn superseded(kind: &str, id: &str, by: &str) {
if use_colors() {
eprintln!("Superseded {}: {}", kind, id.yellow().bold());
eprintln!(" Replaced by: {}", by.cyan().bold());
} else {
eprintln!("Superseded {}: {}", kind, id);
eprintln!(" Replaced by: {}", by);
}
}
pub fn rendered(path: &Path) {
if use_colors() {
eprintln!("{}: {}", "Rendered".green(), path.display().cyan());
} else {
eprintln!("Rendered: {}", path.display());
}
}
pub fn not_found(kind: &str, location: &Path) {
if use_colors() {
eprintln!("No {}s found in {}", kind, location.display().cyan());
} else {
eprintln!("No {}s found in {}", kind, location.display());
}
}
pub fn check_header() {
if use_colors() {
eprintln!("{}:", "Checked".bold());
} else {
eprintln!("Checked:");
}
}
pub fn check_count(count: usize, kind: &str) {
if use_colors() {
eprintln!(" {} {}", count.to_string().cyan().bold(), kind);
} else {
eprintln!(" {} {}", count, kind);
}
}
pub fn render_summary(count: usize, kind: &str) {
if use_colors() {
eprintln!(
"{} Rendered {} {}(s)",
"✓".green(),
count.to_string().cyan().bold(),
kind
);
} else {
eprintln!("✓ Rendered {} {}(s)", count, kind);
}
}
use crate::diagnostic::{Diagnostic, DiagnosticLevel};
pub fn created_path(path: &Path) {
if use_colors() {
eprintln!("{}: {}", "Created".green(), path.display().cyan());
} else {
eprintln!("Created: {}", path.display());
}
}
pub fn updated(kind: &str, id: &str) {
if use_colors() {
eprintln!("Updated {}: {}", kind, id.cyan().bold());
} else {
eprintln!("Updated {}: {}", kind, id);
}
}
pub fn finalized(id: &str, status: &str) {
if use_colors() {
eprintln!(
"Finalized {} to status: {}",
id.cyan().bold(),
status.green()
);
} else {
eprintln!("Finalized {} to status: {}", id, status);
}
}
pub fn release_created(version: &str, date: &str, work_item_count: usize) {
if use_colors() {
eprintln!(
"Created release {} ({}) with {} work items",
version.cyan().bold(),
date,
work_item_count.to_string().green()
);
} else {
eprintln!(
"Created release {} ({}) with {} work items",
version, date, work_item_count
);
}
}
pub fn changelog_rendered(path: &std::path::Path, release_count: usize, unreleased_count: usize) {
if use_colors() {
eprintln!(
"Rendered CHANGELOG to {} ({} releases, {} unreleased)",
path_str(path).cyan(),
release_count,
unreleased_count
);
} else {
eprintln!(
"Rendered CHANGELOG to {} ({} releases, {} unreleased)",
path.display(),
release_count,
unreleased_count
);
}
}
pub fn sub_info(msg: impl Display) {
eprintln!(" {}", msg);
}
pub fn error(msg: impl Display) {
if use_colors() {
eprintln!("{}: {}", "Error".red().bold(), msg);
} else {
eprintln!("Error: {}", msg);
}
}
pub fn dry_run_preview(path: &Path) {
if use_colors() {
eprintln!("{}: {}", "Would write".yellow(), path.display().cyan());
} else {
eprintln!("Would write: {}", path.display());
}
eprintln!("--- Content preview ---");
}
pub fn preview_line(line: &str) {
eprintln!("{}", line);
}
pub fn preview_truncated() {
eprintln!("...");
}
pub fn dry_run_file_preview(path: &Path, content: &str) {
if use_colors() {
eprintln!("{}: {}", "Would write".yellow(), path.display().cyan());
} else {
eprintln!("Would write: {}", path.display());
}
for line in content.lines().take(20) {
eprintln!(" {}", line);
}
if content.lines().count() > 20 {
eprintln!(" ...");
}
}
pub fn dry_run_mkdir(path: &Path) {
if use_colors() {
eprintln!("{}: {}", "Would create dir".yellow(), path.display().cyan());
} else {
eprintln!("Would create dir: {}", path.display());
}
}
pub fn dry_run_move(from: &Path, to: &Path) {
if use_colors() {
eprintln!(
"{}: {} -> {}",
"Would move".yellow(),
from.display().cyan(),
to.display().cyan()
);
} else {
eprintln!("Would move: {} -> {}", from.display(), to.display());
}
}
pub fn dry_run_summary(kind: &str, id: &str, action: &str) {
if use_colors() {
eprintln!(
"{} {} {}: {}",
"Would".yellow(),
action,
kind,
id.cyan().bold()
);
} else {
eprintln!("Would {} {}: {}", action, kind, id);
}
}
pub fn diagnostic(diag: &Diagnostic) {
if use_colors() {
let level_str = match diag.level {
DiagnosticLevel::Error => "error".red().bold().to_string(),
DiagnosticLevel::Warning => "warning".yellow().bold().to_string(),
};
eprintln!(
"{}[{}]: {} ({})",
level_str,
diag.code.code().bright_black(),
diag.message,
diag.file.cyan()
);
} else {
let level_str = match diag.level {
DiagnosticLevel::Error => "error",
DiagnosticLevel::Warning => "warning",
};
eprintln!(
"{}[{}]: {} ({})",
level_str,
diag.code.code(),
diag.message,
diag.file
);
}
}