cli: colorize output in various commands

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I612086bad607a92e4ac1c1f09b41534d6a6a6964
This commit is contained in:
raf 2026-05-03 03:43:29 +03:00
commit 616916cd48
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
4 changed files with 48 additions and 20 deletions

View file

@ -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());
}
}

View file

@ -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());
}
}

View file

@ -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 = <sha1::Sha1 as sha1::Digest>::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 = <sha1::Sha1 as sha1::Digest>::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(())

View file

@ -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<PathBuf> {
let mut current_dir = env::current_dir().ok()?;