Skip to content

Commit 4910db3

Browse files
committed
Auto merge of #12992 - weihanglo:cargo-list, r=
feat(cli): add color output for `cargo --list`
2 parents b340965 + 2890607 commit 4910db3

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/bin/cargo/cli.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,14 @@ Run with 'cargo -Z [FLAG] [COMMAND]'",
134134
"Formats all bin and lib files of the current crate using rustfmt.",
135135
),
136136
]);
137-
drop_println!(config, "Installed Commands:");
137+
drop_println!(
138+
config,
139+
color_print::cstr!("<green,bold>Installed Commands:</>")
140+
);
138141
for (name, command) in list_commands(config) {
139142
let known_external_desc = known_external_command_descriptions.get(name.as_str());
143+
let literal = style::LITERAL.render();
144+
let reset = anstyle::Reset.render();
140145
match command {
141146
CommandInfo::BuiltIn { about } => {
142147
assert!(
@@ -145,22 +150,21 @@ Run with 'cargo -Z [FLAG] [COMMAND]'",
145150
);
146151
let summary = about.unwrap_or_default();
147152
let summary = summary.lines().next().unwrap_or(&summary); // display only the first line
148-
drop_println!(config, " {:<20} {}", name, summary);
153+
drop_println!(config, " {literal}{name:<20}{reset} {summary}");
149154
}
150155
CommandInfo::External { path } => {
151156
if let Some(desc) = known_external_desc {
152-
drop_println!(config, " {:<20} {}", name, desc);
157+
drop_println!(config, " {literal}{name:<20}{reset} {desc}");
153158
} else if is_verbose {
154-
drop_println!(config, " {:<20} {}", name, path.display());
159+
drop_println!(config, " {literal}{name:<20}{reset} {}", path.display());
155160
} else {
156-
drop_println!(config, " {}", name);
161+
drop_println!(config, " {literal}{name}{reset}");
157162
}
158163
}
159164
CommandInfo::Alias { target } => {
160165
drop_println!(
161166
config,
162-
" {:<20} alias: {}",
163-
name,
167+
" {literal}{name:<20}{reset} alias: {}",
164168
target.iter().join(" ")
165169
);
166170
}

0 commit comments

Comments
 (0)