diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-02-23 01:42:28 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-02-23 01:42:28 +0900 |
| commit | ae0f9c3ced9d07964a0bf2fe76f745aacc7dd34a (patch) | |
| tree | 964602f8ca32759c1e1de2c88f0871a673a8f1f4 /crates/mozart/src/commands | |
| parent | 82c89125dc6a1620ecd80949c155295a96db408c (diff) | |
| download | php-mozart-ae0f9c3ced9d07964a0bf2fe76f745aacc7dd34a.tar.gz php-mozart-ae0f9c3ced9d07964a0bf2fe76f745aacc7dd34a.tar.zst php-mozart-ae0f9c3ced9d07964a0bf2fe76f745aacc7dd34a.zip | |
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 <noreply@anthropic.com>
Diffstat (limited to 'crates/mozart/src/commands')
| -rw-r--r-- | crates/mozart/src/commands/search.rs | 45 |
1 files changed, 18 insertions, 27 deletions
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!(" <warning>! Abandoned !</warning>") + 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!("<info>{:<width$}</info>", result.name, width = name_width), - console_format!("<comment>{}</comment>", dl_str), - console_format!("<comment>{}</comment>", 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); } } } |
