aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock11
-rw-r--r--Cargo.toml1
-rw-r--r--crates/mozart/Cargo.toml1
-rw-r--r--crates/mozart/src/commands/search.rs45
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",
@@ -1933,6 +1934,16 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
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!(" <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);
}
}
}