From 616916cd488d32fcfff0b07bd4653a0ebeb0811d Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 3 May 2026 03:43:29 +0300 Subject: [PATCH] cli: colorize output in various commands Signed-off-by: NotAShelf Change-Id: I612086bad607a92e4ac1c1f09b41534d6a6a6964 --- crates/pakker-cli/src/cli/commands/diff.rs | 4 ++- crates/pakker-cli/src/cli/commands/fork.rs | 11 +++---- crates/pakker-cli/src/cli/commands/sync.rs | 34 ++++++++++++++++------ crates/pakker-cli/src/lib.rs | 19 ++++++++---- 4 files changed, 48 insertions(+), 20 deletions(-) diff --git a/crates/pakker-cli/src/cli/commands/diff.rs b/crates/pakker-cli/src/cli/commands/diff.rs index 23f34d5..ecbbb42 100644 --- a/crates/pakker-cli/src/cli/commands/diff.rs +++ b/crates/pakker-cli/src/cli/commands/diff.rs @@ -5,6 +5,8 @@ use std::{ path::Path, }; +use yansi::Paint; + use crate::{cli::DiffArgs, error::Result, model::LockFile}; #[derive(Debug)] @@ -244,7 +246,7 @@ fn print_terminal_diff( && !loader_changes && changes.is_empty() { - println!("✓ No differences found"); + println!("{}", "✓ No differences found".green()); } } diff --git a/crates/pakker-cli/src/cli/commands/fork.rs b/crates/pakker-cli/src/cli/commands/fork.rs index 96b22af..61ab9b2 100644 --- a/crates/pakker-cli/src/cli/commands/fork.rs +++ b/crates/pakker-cli/src/cli/commands/fork.rs @@ -7,6 +7,7 @@ use std::{ }; use indicatif::{ProgressBar, ProgressStyle}; +use yansi::Paint; use crate::{ cli::ForkArgs, @@ -367,7 +368,7 @@ fn execute_init( add_to_gitignore()?; println!(); - println!("✓ Fork initialized successfully"); + println!("{}", "✓ Fork initialized successfully".green()); println!(" Parent: {url}"); println!(" Ref: {} ({})", resolved_ref, match resolved_ref_type { RefType::Branch => "branch", @@ -414,7 +415,7 @@ fn execute_set( local_config.parent = Some(parent.clone()); local_config.save(config_dir)?; - println!("✓ Fork configuration updated"); + println!("{}", "✓ Fork configuration updated".green()); println!(" Parent: {}", parent.id); println!(" Ref: {} ({})", parent.ref_, match parent.ref_type { RefType::Branch => "branch", @@ -515,7 +516,7 @@ fn execute_unset() -> Result<(), PakkerError> { local_config.parent_config_hash = None; local_config.save(config_dir)?; - println!("✓ Fork configuration removed"); + println!("{}", "✓ Fork configuration removed".green()); Ok(()) } @@ -640,7 +641,7 @@ fn execute_sync() -> Result<(), PakkerError> { local_config.save(config_dir)?; println!(); - println!("✓ Parent sync complete"); + println!("{}", "✓ Parent sync complete".green()); println!(" Commit: {}", &commit_sha[..8]); // Print diff of parent changes @@ -678,7 +679,7 @@ fn execute_sync() -> Result<(), PakkerError> { for (slug, old_file, new_file) in updated { let old = old_file.as_deref().unwrap_or("?"); let new = new_file.as_deref().unwrap_or("?"); - println!(" ~ {slug}: {old} → {new}"); + println!(" {} {slug}: {old} → {new}", "~".yellow()); } } diff --git a/crates/pakker-cli/src/cli/commands/sync.rs b/crates/pakker-cli/src/cli/commands/sync.rs index 1963ba7..a999147 100644 --- a/crates/pakker-cli/src/cli/commands/sync.rs +++ b/crates/pakker-cli/src/cli/commands/sync.rs @@ -5,6 +5,7 @@ use std::{ }; use indicatif::{ProgressBar, ProgressStyle}; +use yansi::Paint; use crate::{ cli::SyncArgs, @@ -41,7 +42,7 @@ pub async fn execute( let changes = detect_changes(&lockfile, &config); if changes.is_empty() { - println!("✓ Everything is in sync"); + println!("{}", "✓ Everything is in sync".green()); return Ok(()); } @@ -79,7 +80,7 @@ pub async fn execute( )? && let Ok(file_data) = fs::read(file_path) { use sha1::Digest; - let mut hasher = sha1::Sha1::new(); + let mut hasher = ::new(); hasher.update(&file_data); let hash = crate::utils::hash::hash_to_hex(hasher.finalize().as_slice()); @@ -145,7 +146,7 @@ pub async fn execute( let fetcher = Fetcher::new("."); fetcher.sync(&lockfile, &config).await?; - println!("✓ Sync complete"); + println!("{}", "✓ Sync complete".green()); Ok(()) } @@ -221,25 +222,34 @@ async fn add_file_to_lockfile( // Compute file hash let file_data = fs::read(file_path)?; - let mut hasher = sha1::Sha1::new(); + let mut hasher = ::new(); hasher.update(&file_data); let hash = crate::utils::hash::hash_to_hex(hasher.finalize().as_slice()); // Try Modrinth first (SHA-1 hash) if let Ok(Some(project)) = modrinth.lookup_by_hash(&hash).await { lockfile.add_project(project); - println!("✓ Added {} (from Modrinth)", file_path.display()); + println!( + "{}", + format!("✓ Added {} (from Modrinth)", file_path.display()).green() + ); return Ok(()); } // Try CurseForge (Murmur2 hash computed from file) if let Ok(Some(project)) = curseforge.lookup_by_hash(&hash).await { lockfile.add_project(project); - println!("✓ Added {} (from CurseForge)", file_path.display()); + println!( + "{}", + format!("✓ Added {} (from CurseForge)", file_path.display()).green() + ); return Ok(()); } - println!("⚠ Could not identify {}, skipping", file_path.display()); + println!( + "{}", + format!("⚠ Could not identify {}, skipping", file_path.display()).yellow() + ); Ok(()) } @@ -291,7 +301,10 @@ async fn add_files_batch( lockfile.add_project(project.clone()); added_pakku_ids.insert(pakku_id.clone()); matched_indices.insert(idx); - println!("✓ Added {} (from Modrinth)", fh.path.display()); + println!( + "{}", + format!("✓ Added {} (from Modrinth)", fh.path.display()).green() + ); break; } } @@ -302,7 +315,10 @@ async fn add_files_batch( if matched_indices.contains(&idx) { continue; } - println!("⚠ Could not identify {}, skipping", fh.path.display()); + println!( + "{}", + format!("⚠ Could not identify {}, skipping", fh.path.display()).yellow() + ); } Ok(()) diff --git a/crates/pakker-cli/src/lib.rs b/crates/pakker-cli/src/lib.rs index 503c82d..f1074bb 100644 --- a/crates/pakker-cli/src/lib.rs +++ b/crates/pakker-cli/src/lib.rs @@ -13,13 +13,22 @@ use clap::Parser; pub mod cli; -pub use pakker_core::{ - error, export, fetch, git, http, ipc, model, platform, rate_limiter, resolver, - ui_utils, utils, -}; - use cli::{Cli, Commands}; use error::PakkerError; +pub use pakker_core::{ + error, + export, + fetch, + git, + http, + ipc, + model, + platform, + rate_limiter, + resolver, + ui_utils, + utils, +}; fn find_working_directory() -> Option { let mut current_dir = env::current_dir().ok()?;