Skip to content

Commit 0dd55e8

Browse files
committed
Auto merge of #4701 - mathstuf:update-lockfile-color-reflects-change, r=alexcrichton
cargo_generate_lockfile: use color to also indicate the change In English, `Updating` and `Removing` are the same length and scanning the list for changes is hard. Use color to help indicate the kind of change that is occurring.
2 parents bac4884 + 7d5c364 commit 0dd55e8

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/cargo/ops/cargo_generate_lockfile.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::collections::{BTreeMap, HashSet};
22

3+
use termcolor::Color::{self, Cyan, Green, Red};
4+
35
use core::PackageId;
46
use core::registry::PackageRegistry;
57
use core::{Resolve, SourceId, Workspace};
@@ -83,8 +85,8 @@ pub fn update_lockfile(ws: &Workspace, opts: &UpdateOptions)
8385
true)?;
8486

8587
// Summarize what is changing for the user.
86-
let print_change = |status: &str, msg: String| {
87-
opts.config.shell().status(status, msg)
88+
let print_change = |status: &str, msg: String, color: Color| {
89+
opts.config.shell().status_with_color(status, msg, color)
8890
};
8991
for (removed, added) in compare_dependency_graphs(&previous_resolve, &resolve) {
9092
if removed.len() == 1 && added.len() == 1 {
@@ -94,13 +96,13 @@ pub fn update_lockfile(ws: &Workspace, opts: &UpdateOptions)
9496
} else {
9597
format!("{} -> v{}", removed[0], added[0].version())
9698
};
97-
print_change("Updating", msg)?;
99+
print_change("Updating", msg, Cyan)?;
98100
} else {
99101
for package in removed.iter() {
100-
print_change("Removing", format!("{}", package))?;
102+
print_change("Removing", format!("{}", package), Red)?;
101103
}
102104
for package in added.iter() {
103-
print_change("Adding", format!("{}", package))?;
105+
print_change("Adding", format!("{}", package), Green)?;
104106
}
105107
}
106108
}

0 commit comments

Comments
 (0)