Skip to content

Commit b1a3ad2

Browse files
committed
Auto merge of #12890 - hi-rustin:rustin-patch-search, r=weihanglo
Improve the margin calculation for the search command's UI
2 parents 04621e2 + cb901f2 commit b1a3ad2

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/cargo/ops/registry/search.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! [1]: https://doc.rust-lang.org/nightly/cargo/reference/registry-web-api.html#search
44
55
use std::cmp;
6-
use std::iter::repeat;
76

87
use anyhow::Context as _;
98
use url::Url;
@@ -35,7 +34,7 @@ pub fn search(
3534
.map(|krate| format!("{} = \"{}\"", krate.name, krate.max_version))
3635
.collect::<Vec<String>>();
3736

38-
let description_margin = names.iter().map(|s| s.len() + 4).max().unwrap_or_default();
37+
let description_margin = names.iter().map(|s| s.len()).max().unwrap_or_default() + 4;
3938

4039
let description_length = cmp::max(80, 128 - description_margin);
4140

@@ -53,12 +52,7 @@ pub fn search(
5352

5453
for (name, description) in names.into_iter().zip(descriptions) {
5554
let line = match description {
56-
Some(desc) => {
57-
let space = repeat(' ')
58-
.take(description_margin - name.len())
59-
.collect::<String>();
60-
name + &space + "# " + &desc
61-
}
55+
Some(desc) => format!("{name: <description_margin$}# {desc}"),
6256
None => name,
6357
};
6458
let mut fragments = line.split(query).peekable();

0 commit comments

Comments
 (0)