Skip to content

Commit 6bbe2cb

Browse files
committed
refactor: Centralizee cargo-tree styling
1 parent 1e7bad8 commit 6bbe2cb

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,14 @@ pub const UPDATE_REMOVED: Style = ERROR;
1818
pub const UPDATE_UPGRADED: Style = GOOD;
1919
pub const UPDATE_DOWNGRADED: Style = WARN;
2020
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)