From ae0f9c3ced9d07964a0bf2fe76f745aacc7dd34a Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 23 Feb 2026 01:42:28 +0900 Subject: fix(search): match Composer single-line output format with truncation Replace two-line output (name+counts, indented description) with Composer's single-line aligned format: padded name, abandoned warning, and terminal-width-aware description truncation. Remove summary header and download/faver count display from text output. Co-Authored-By: Claude Opus 4.6 --- Cargo.lock | 11 +++++++++ Cargo.toml | 1 + crates/mozart/Cargo.toml | 1 + crates/mozart/src/commands/search.rs | 45 +++++++++++++++--------------------- 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b692f5b..fd30568 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1089,6 +1089,7 @@ dependencies = [ "serde_json", "sha1", "tempfile", + "terminal_size", "tokio", "tracing", "tracing-subscriber", @@ -1932,6 +1933,16 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "terminal_size" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b8cb979cb11c32ce1603f8137b22262a9d131aaa5c37b5678025f22b8becd0" +dependencies = [ + "rustix", + "windows-sys 0.60.2", +] + [[package]] name = "termtree" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index 4c7949e..5d972b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,7 @@ serde_json = "1.0.149" sha1 = "0.10.6" syn = { version = "2.0.117", features = ["full", "parsing"] } tar = "0.4.44" +terminal_size = "0.4" tempfile = "3.25.0" tokio = { version = "1.49.0", features = ["full"] } tracing = "0.1.44" diff --git a/crates/mozart/Cargo.toml b/crates/mozart/Cargo.toml index 599c2a1..915273b 100644 --- a/crates/mozart/Cargo.toml +++ b/crates/mozart/Cargo.toml @@ -20,6 +20,7 @@ serde.workspace = true serde_json.workspace = true sha1.workspace = true tempfile.workspace = true +terminal_size.workspace = true tokio.workspace = true url.workspace = true tracing-subscriber.workspace = true diff --git a/crates/mozart/src/commands/search.rs b/crates/mozart/src/commands/search.rs index bca4903..6da85f9 100644 --- a/crates/mozart/src/commands/search.rs +++ b/crates/mozart/src/commands/search.rs @@ -50,6 +50,7 @@ pub struct SearchArgs { } /// Format a large count as a human-readable string (e.g. 1500 -> "1.5K", 2500000 -> "2.5M"). +#[allow(dead_code)] fn format_count(n: u64) -> String { if n >= 1_000_000 { let m = n as f64 / 1_000_000.0; @@ -123,7 +124,7 @@ pub async fn execute( std::process::exit(1); } - let (all_results, total) = + let (all_results, _total) = mozart_registry::packagist::search_packages(&query, args.r#type.as_deref()).await?; // Apply client-side filters @@ -187,38 +188,28 @@ pub async fn execute( return Ok(()); } - eprintln!( - "Found {} packages matching \"{}\" (showing {} result{})", - total, - query, - results.len(), - if results.len() == 1 { "" } else { "s" } - ); - eprintln!(); - - // Calculate alignment widths - let name_width = results.iter().map(|r| r.name.len()).max().unwrap_or(0); + let width = terminal_size::terminal_size() + .map(|(w, _)| w.0 as usize) + .unwrap_or(80); + let name_width = results.iter().map(|r| r.name.len()).max().unwrap_or(0) + 1; for result in &results { - let dl_str = format!("Downloads: {}", format_count(result.downloads)); - let fav_str = format!("Favers: {}", format_count(result.favers)); + let warning = if is_abandoned(result) { + "! Abandoned ! " + } else { + "" + }; - let abandoned_warning = if is_abandoned(result) { - console_format!(" ! Abandoned !") + let remaining = width.saturating_sub(name_width + warning.len()); + let description = result.description.as_str(); + let desc_display = if description.len() > remaining && remaining > 3 { + format!("{}...", &description[..remaining.saturating_sub(3)]) } else { - String::new() + description.to_string() }; - println!( - "{} {} {}{}", - console_format!("{:", result.name, width = name_width), - console_format!("{}", dl_str), - console_format!("{}", fav_str), - abandoned_warning, - ); - if !result.description.is_empty() { - println!(" {}", result.description); - } + let padding = " ".repeat(name_width.saturating_sub(result.name.len())); + println!("{}{}{}{}", result.name, padding, warning, desc_display); } } } -- cgit v1.3.1