Skip to content

Commit d80156f

Browse files
authored
refactor: Centralize some more styling (#16124)
### What does this PR try to resolve? On its own, this does nothing. These styles aren't used anywhere else and so this doesn't increase re-use. My primary goal with this is having a central place to document this for other applications to track that want to mirror our style. In particular, I'm hoping to take advantage of the `UPDATE` colors in rustup. This also makes it easier for us to audit all of the values for consistency. ### How to test and review this PR?
2 parents 367fd9f + 6bbe2cb commit d80156f

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

src/cargo/ops/cargo_update.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,11 +1058,11 @@ impl PackageChangeKind {
10581058

10591059
pub fn style(&self) -> anstyle::Style {
10601060
match self {
1061-
Self::Added => style::NOTE,
1062-
Self::Removed => style::ERROR,
1063-
Self::Upgraded => style::GOOD,
1064-
Self::Downgraded => style::WARN,
1065-
Self::Unchanged => anstyle::Style::new().bold(),
1061+
Self::Added => style::UPDATE_ADDED,
1062+
Self::Removed => style::UPDATE_REMOVED,
1063+
Self::Upgraded => style::UPDATE_UPGRADED,
1064+
Self::Downgraded => style::UPDATE_DOWNGRADED,
1065+
Self::Unchanged => style::UPDATE_UNCHANGED,
10661066
}
10671067
}
10681068
}

src/cargo/ops/tree/mod.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::core::{Package, PackageId, PackageIdSpec, PackageIdSpecQuery, Workspa
88
use crate::ops::resolve::SpecsAndResolvedFeatures;
99
use crate::ops::{self, Packages};
1010
use crate::util::CargoResult;
11+
use crate::util::style;
1112
use crate::{drop_print, drop_println};
1213
use anyhow::Context as _;
1314
use graph::Graph;
@@ -477,13 +478,9 @@ fn print_dependencies<'a>(
477478

478479
fn edge_line_color(kind: EdgeKind) -> anstyle::Style {
479480
match kind {
480-
EdgeKind::Dep(DepKind::Normal) => anstyle::Style::new() | anstyle::Effects::DIMMED,
481-
EdgeKind::Dep(DepKind::Build) => {
482-
anstyle::AnsiColor::Blue.on_default() | anstyle::Effects::BOLD
483-
}
484-
EdgeKind::Dep(DepKind::Development) => {
485-
anstyle::AnsiColor::Cyan.on_default() | anstyle::Effects::BOLD
486-
}
487-
EdgeKind::Feature => anstyle::AnsiColor::Magenta.on_default() | anstyle::Effects::DIMMED,
481+
EdgeKind::Dep(DepKind::Normal) => style::DEP_NORMAL,
482+
EdgeKind::Dep(DepKind::Build) => style::DEP_BUILD,
483+
EdgeKind::Dep(DepKind::Development) => style::DEP_DEV,
484+
EdgeKind::Feature => style::DEP_FEATURE,
488485
}
489486
}

src/cargo/util/style.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,20 @@ pub const GOOD: Style = AnsiColor::BrightGreen.on_default().effects(Effects::BOL
1212
pub const VALID: Style = AnsiColor::BrightCyan.on_default().effects(Effects::BOLD);
1313
pub const INVALID: Style = annotate_snippets::renderer::DEFAULT_WARNING_STYLE;
1414
pub const TRANSIENT: Style = annotate_snippets::renderer::DEFAULT_HELP_STYLE;
15+
16+
pub const UPDATE_ADDED: Style = NOTE;
17+
pub const UPDATE_REMOVED: Style = ERROR;
18+
pub const UPDATE_UPGRADED: Style = GOOD;
19+
pub const UPDATE_DOWNGRADED: Style = WARN;
20+
pub const UPDATE_UNCHANGED: Style = anstyle::Style::new().bold();
21+
22+
pub const DEP_NORMAL: Style = anstyle::Style::new().effects(anstyle::Effects::DIMMED);
23+
pub const DEP_BUILD: Style = anstyle::AnsiColor::Blue
24+
.on_default()
25+
.effects(anstyle::Effects::BOLD);
26+
pub const DEP_DEV: Style = anstyle::AnsiColor::Cyan
27+
.on_default()
28+
.effects(anstyle::Effects::BOLD);
29+
pub const DEP_FEATURE: Style = anstyle::AnsiColor::Magenta
30+
.on_default()
31+
.effects(anstyle::Effects::DIMMED);

0 commit comments

Comments
 (0)