Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/cargo/ops/cargo_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,11 +1058,11 @@ impl PackageChangeKind {

pub fn style(&self) -> anstyle::Style {
match self {
Self::Added => style::NOTE,
Self::Removed => style::ERROR,
Self::Upgraded => style::GOOD,
Self::Downgraded => style::WARN,
Self::Unchanged => anstyle::Style::new().bold(),
Self::Added => style::UPDATE_ADDED,
Self::Removed => style::UPDATE_REMOVED,
Self::Upgraded => style::UPDATE_UPGRADED,
Self::Downgraded => style::UPDATE_DOWNGRADED,
Self::Unchanged => style::UPDATE_UNCHANGED,
}
}
}
Expand Down
13 changes: 5 additions & 8 deletions src/cargo/ops/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::core::{Package, PackageId, PackageIdSpec, PackageIdSpecQuery, Workspa
use crate::ops::resolve::SpecsAndResolvedFeatures;
use crate::ops::{self, Packages};
use crate::util::CargoResult;
use crate::util::style;
use crate::{drop_print, drop_println};
use anyhow::Context as _;
use graph::Graph;
Expand Down Expand Up @@ -477,13 +478,9 @@ fn print_dependencies<'a>(

fn edge_line_color(kind: EdgeKind) -> anstyle::Style {
match kind {
EdgeKind::Dep(DepKind::Normal) => anstyle::Style::new() | anstyle::Effects::DIMMED,
EdgeKind::Dep(DepKind::Build) => {
anstyle::AnsiColor::Blue.on_default() | anstyle::Effects::BOLD
}
EdgeKind::Dep(DepKind::Development) => {
anstyle::AnsiColor::Cyan.on_default() | anstyle::Effects::BOLD
}
EdgeKind::Feature => anstyle::AnsiColor::Magenta.on_default() | anstyle::Effects::DIMMED,
EdgeKind::Dep(DepKind::Normal) => style::DEP_NORMAL,
EdgeKind::Dep(DepKind::Build) => style::DEP_BUILD,
EdgeKind::Dep(DepKind::Development) => style::DEP_DEV,
EdgeKind::Feature => style::DEP_FEATURE,
}
}
17 changes: 17 additions & 0 deletions src/cargo/util/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,20 @@ pub const GOOD: Style = AnsiColor::BrightGreen.on_default().effects(Effects::BOL
pub const VALID: Style = AnsiColor::BrightCyan.on_default().effects(Effects::BOLD);
pub const INVALID: Style = annotate_snippets::renderer::DEFAULT_WARNING_STYLE;
pub const TRANSIENT: Style = annotate_snippets::renderer::DEFAULT_HELP_STYLE;

pub const UPDATE_ADDED: Style = NOTE;
pub const UPDATE_REMOVED: Style = ERROR;
pub const UPDATE_UPGRADED: Style = GOOD;
pub const UPDATE_DOWNGRADED: Style = WARN;
pub const UPDATE_UNCHANGED: Style = anstyle::Style::new().bold();

pub const DEP_NORMAL: Style = anstyle::Style::new().effects(anstyle::Effects::DIMMED);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My primary goal with this is having a central place to document this for other applications

Do you mean we'll have doc comments for each, or code itself is self-documented?

Ask because I don't think the variable names here describe the intent clear if not looking into the implementation

But anyway, having styles in one place is great.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean we'll have doc comments for each, or code itself is self-documented?

Not quite either. I more care about having this specified in a central location to copy/paste from. annotate-snippets makes that copy/pasting more complex but oh well.

pub const DEP_BUILD: Style = anstyle::AnsiColor::Blue
.on_default()
.effects(anstyle::Effects::BOLD);
pub const DEP_DEV: Style = anstyle::AnsiColor::Cyan
.on_default()
.effects(anstyle::Effects::BOLD);
pub const DEP_FEATURE: Style = anstyle::AnsiColor::Magenta
.on_default()
.effects(anstyle::Effects::DIMMED);