diff --git a/src/cargo/ops/registry/search.rs b/src/cargo/ops/registry/search.rs index 10b4d600e6b..2672e0ecabb 100644 --- a/src/cargo/ops/registry/search.rs +++ b/src/cargo/ops/registry/search.rs @@ -46,6 +46,11 @@ pub fn search( .map(|desc| truncate_with_ellipsis(&desc.replace("\n", " "), description_length)) }); + let mut shell = config.shell(); + let stdout = shell.out(); + let good = style::GOOD.render(); + let reset = anstyle::Reset.render(); + for (name, description) in names.into_iter().zip(descriptions) { let line = match description { Some(desc) => { @@ -58,22 +63,20 @@ pub fn search( }; let mut fragments = line.split(query).peekable(); while let Some(fragment) = fragments.next() { - let _ = config.shell().write_stdout(fragment, &style::NOP); + let _ = write!(stdout, "{fragment}"); if fragments.peek().is_some() { - let _ = config.shell().write_stdout(query, &style::GOOD); + let _ = write!(stdout, "{good}{query}{reset}"); } } - let _ = config.shell().write_stdout("\n", &style::NOP); + let _ = writeln!(stdout); } let search_max_limit = 100; if total_crates > limit && limit < search_max_limit { - let _ = config.shell().write_stdout( - format_args!( - "... and {} crates more (use --limit N to see more)\n", - total_crates - limit - ), - &style::NOP, + let _ = writeln!( + stdout, + "... and {} crates more (use --limit N to see more)", + total_crates - limit ); } else if total_crates > limit && limit >= search_max_limit { let extra = if source_ids.original.is_crates_io() { @@ -82,9 +85,11 @@ pub fn search( } else { String::new() }; - let _ = config.shell().write_stdout( - format_args!("... and {} crates more{}\n", total_crates - limit, extra), - &style::NOP, + let _ = writeln!( + stdout, + "... and {} crates more{}", + total_crates - limit, + extra ); }