From cb901f21cb7b8d8646f6ee9c890eb5cb6e7cf08d Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Sat, 28 Oct 2023 20:34:02 +0800 Subject: [PATCH] Improve the margin calculation for the search command's UI Signed-off-by: hi-rustin --- src/cargo/ops/registry/search.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/cargo/ops/registry/search.rs b/src/cargo/ops/registry/search.rs index 2672e0ecabb..0f464975406 100644 --- a/src/cargo/ops/registry/search.rs +++ b/src/cargo/ops/registry/search.rs @@ -3,7 +3,6 @@ //! [1]: https://doc.rust-lang.org/nightly/cargo/reference/registry-web-api.html#search use std::cmp; -use std::iter::repeat; use anyhow::Context as _; use url::Url; @@ -35,7 +34,7 @@ pub fn search( .map(|krate| format!("{} = \"{}\"", krate.name, krate.max_version)) .collect::>(); - let description_margin = names.iter().map(|s| s.len() + 4).max().unwrap_or_default(); + let description_margin = names.iter().map(|s| s.len()).max().unwrap_or_default() + 4; let description_length = cmp::max(80, 128 - description_margin); @@ -53,12 +52,7 @@ pub fn search( for (name, description) in names.into_iter().zip(descriptions) { let line = match description { - Some(desc) => { - let space = repeat(' ') - .take(description_margin - name.len()) - .collect::(); - name + &space + "# " + &desc - } + Some(desc) => format!("{name: name, }; let mut fragments = line.split(query).peekable();