Skip to content

Commit b73d4b1

Browse files
committed
feat: Expose cargo's new styling
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.
1 parent 14419ba commit b73d4b1

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ default = ["clap"]
4141
clap = ["dep:clap"]
4242

4343
[dependencies]
44+
anstyle = "1.0.3"
4445
cargo_metadata = { version = "0.17", optional = true }
4546
clap = { version = "4.4.1", default-features = false, features = ["std", "derive"], optional = true }
4647

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ mod features;
4545
mod manifest;
4646
mod workspace;
4747

48+
pub mod style;
49+
4850
pub use features::*;
4951
pub use manifest::*;
5052
pub use workspace::*;

src/style.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use anstyle::*;
2+
3+
pub const NOP: Style = Style::new();
4+
pub const HEADER: Style = AnsiColor::Green.on_default().effects(Effects::BOLD);
5+
pub const USAGE: Style = AnsiColor::Green.on_default().effects(Effects::BOLD);
6+
pub const LITERAL: Style = AnsiColor::Cyan.on_default().effects(Effects::BOLD);
7+
pub const PLACEHOLDER: Style = AnsiColor::Cyan.on_default();
8+
pub const ERROR: Style = AnsiColor::Red.on_default().effects(Effects::BOLD);
9+
pub const WARN: Style = AnsiColor::Yellow.on_default().effects(Effects::BOLD);
10+
pub const NOTE: Style = AnsiColor::Cyan.on_default().effects(Effects::BOLD);
11+
pub const GOOD: Style = AnsiColor::Green.on_default().effects(Effects::BOLD);
12+
pub const VALID: Style = AnsiColor::Cyan.on_default().effects(Effects::BOLD);
13+
pub const INVALID: Style = AnsiColor::Yellow.on_default().effects(Effects::BOLD);
14+
15+
#[cfg(feature = "clap")]
16+
pub const CLAP_STYLING: clap::builder::styling::Styles = clap::builder::styling::Styles::styled()
17+
.header(HEADER)
18+
.usage(USAGE)
19+
.literal(LITERAL)
20+
.placeholder(PLACEHOLDER)
21+
.error(ERROR)
22+
.valid(VALID)
23+
.invalid(INVALID);

0 commit comments

Comments
 (0)