Skip to content

Commit

Permalink
feat: Expose cargo's new styling
Browse files Browse the repository at this point in the history
This mirrors what the API in rust-lang/cargo#12655.  I'm hoping to have
the `anstyle` consts be a public crate owned by the cargo team in the
future after which we'll refactor to re-export it.

See rust-lang/cargo#12578 for adding the style.
  • Loading branch information
epage committed Sep 11, 2023
1 parent 14419ba commit b73d4b1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ default = ["clap"]
clap = ["dep:clap"]

[dependencies]
anstyle = "1.0.3"
cargo_metadata = { version = "0.17", optional = true }
clap = { version = "4.4.1", default-features = false, features = ["std", "derive"], optional = true }

Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ mod features;
mod manifest;
mod workspace;

pub mod style;

pub use features::*;
pub use manifest::*;
pub use workspace::*;
23 changes: 23 additions & 0 deletions src/style.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use anstyle::*;

pub const NOP: Style = Style::new();
pub const HEADER: Style = AnsiColor::Green.on_default().effects(Effects::BOLD);
pub const USAGE: Style = AnsiColor::Green.on_default().effects(Effects::BOLD);
pub const LITERAL: Style = AnsiColor::Cyan.on_default().effects(Effects::BOLD);
pub const PLACEHOLDER: Style = AnsiColor::Cyan.on_default();
pub const ERROR: Style = AnsiColor::Red.on_default().effects(Effects::BOLD);
pub const WARN: Style = AnsiColor::Yellow.on_default().effects(Effects::BOLD);
pub const NOTE: Style = AnsiColor::Cyan.on_default().effects(Effects::BOLD);
pub const GOOD: Style = AnsiColor::Green.on_default().effects(Effects::BOLD);
pub const VALID: Style = AnsiColor::Cyan.on_default().effects(Effects::BOLD);
pub const INVALID: Style = AnsiColor::Yellow.on_default().effects(Effects::BOLD);

#[cfg(feature = "clap")]
pub const CLAP_STYLING: clap::builder::styling::Styles = clap::builder::styling::Styles::styled()
.header(HEADER)
.usage(USAGE)
.literal(LITERAL)
.placeholder(PLACEHOLDER)
.error(ERROR)
.valid(VALID)
.invalid(INVALID);

0 comments on commit b73d4b1

Please sign in to comment.