clap_cargo/
style.rs

1#![allow(missing_docs)]
2#![allow(unused_qualifications)] // for copy/paste sake
3#![allow(unreachable_pub)] // for copy/paste sake
4
5use anstyle::AnsiColor;
6use anstyle::Effects;
7use anstyle::Style;
8
9pub const NOP: Style = Style::new();
10pub const HEADER: Style = AnsiColor::BrightGreen.on_default().effects(Effects::BOLD);
11pub const USAGE: Style = AnsiColor::BrightGreen.on_default().effects(Effects::BOLD);
12pub const LITERAL: Style = AnsiColor::BrightCyan.on_default().effects(Effects::BOLD);
13pub const PLACEHOLDER: Style = AnsiColor::Cyan.on_default();
14pub const ERROR: Style = annotate_snippets::renderer::DEFAULT_ERROR_STYLE;
15pub const WARN: Style = annotate_snippets::renderer::DEFAULT_WARNING_STYLE;
16pub const NOTE: Style = annotate_snippets::renderer::DEFAULT_NOTE_STYLE;
17pub const GOOD: Style = AnsiColor::BrightGreen.on_default().effects(Effects::BOLD);
18pub const VALID: Style = AnsiColor::BrightCyan.on_default().effects(Effects::BOLD);
19pub const INVALID: Style = annotate_snippets::renderer::DEFAULT_WARNING_STYLE;
20pub const TRANSIENT: Style = annotate_snippets::renderer::DEFAULT_HELP_STYLE;
21pub const CONTEXT: Style = annotate_snippets::renderer::DEFAULT_CONTEXT_STYLE;
22
23pub const UPDATE_ADDED: Style = NOTE;
24pub const UPDATE_REMOVED: Style = ERROR;
25pub const UPDATE_UPGRADED: Style = GOOD;
26pub const UPDATE_DOWNGRADED: Style = WARN;
27pub const UPDATE_UNCHANGED: Style = anstyle::Style::new().bold();
28
29pub const DEP_NORMAL: Style = anstyle::Style::new().effects(anstyle::Effects::DIMMED);
30pub const DEP_BUILD: Style = anstyle::AnsiColor::Blue
31    .on_default()
32    .effects(anstyle::Effects::BOLD);
33pub const DEP_DEV: Style = anstyle::AnsiColor::Cyan
34    .on_default()
35    .effects(anstyle::Effects::BOLD);
36pub const DEP_FEATURE: Style = anstyle::AnsiColor::Magenta
37    .on_default()
38    .effects(anstyle::Effects::DIMMED);
39
40/// For use with
41/// [`clap::Command::styles`](https://docs.rs/clap/latest/clap/struct.Command.html#method.styles)
42#[cfg(feature = "clap")]
43pub const CLAP_STYLING: clap::builder::styling::Styles = clap::builder::styling::Styles::styled()
44    .header(HEADER)
45    .usage(USAGE)
46    .literal(LITERAL)
47    .placeholder(PLACEHOLDER)
48    .error(ERROR)
49    .valid(VALID)
50    .invalid(INVALID);
51
52// Copied from https://github.com/rust-lang/annotate-snippets-rs/blob/5a632cdfadb5902bf063722f80b37fcb50da0416/src/renderer/mod.rs
53mod annotate_snippets {
54    pub mod renderer {
55        #![allow(dead_code)] // for copy/paste sake
56        #![allow(rustdoc::broken_intra_doc_links)] // for copy/paste sake
57        use anstyle::{AnsiColor, Effects, Style};
58
59        const USE_WINDOWS_COLORS: bool = cfg!(windows) && !cfg!(feature = "testing_colors");
60        const BRIGHT_BLUE: Style = if USE_WINDOWS_COLORS {
61            AnsiColor::BrightCyan.on_default()
62        } else {
63            AnsiColor::BrightBlue.on_default()
64        };
65        /// [`Renderer::error`] applied by [`Renderer::styled`]
66        pub const DEFAULT_ERROR_STYLE: Style =
67            AnsiColor::BrightRed.on_default().effects(Effects::BOLD);
68        /// [`Renderer::warning`] applied by [`Renderer::styled`]
69        pub const DEFAULT_WARNING_STYLE: Style = if USE_WINDOWS_COLORS {
70            AnsiColor::BrightYellow.on_default()
71        } else {
72            AnsiColor::Yellow.on_default()
73        }
74        .effects(Effects::BOLD);
75        /// [`Renderer::info`] applied by [`Renderer::styled`]
76        pub const DEFAULT_INFO_STYLE: Style = BRIGHT_BLUE.effects(Effects::BOLD);
77        /// [`Renderer::note`] applied by [`Renderer::styled`]
78        pub const DEFAULT_NOTE_STYLE: Style =
79            AnsiColor::BrightGreen.on_default().effects(Effects::BOLD);
80        /// [`Renderer::help`] applied by [`Renderer::styled`]
81        pub const DEFAULT_HELP_STYLE: Style =
82            AnsiColor::BrightCyan.on_default().effects(Effects::BOLD);
83        /// [`Renderer::line_num`] applied by [`Renderer::styled`]
84        pub const DEFAULT_LINE_NUM_STYLE: Style = BRIGHT_BLUE.effects(Effects::BOLD);
85        /// [`Renderer::emphasis`] applied by [`Renderer::styled`]
86        pub const DEFAULT_EMPHASIS_STYLE: Style = if USE_WINDOWS_COLORS {
87            AnsiColor::BrightWhite.on_default()
88        } else {
89            Style::new()
90        }
91        .effects(Effects::BOLD);
92        /// [`Renderer::none`] applied by [`Renderer::styled`]
93        pub const DEFAULT_NONE_STYLE: Style = Style::new();
94        /// [`Renderer::context`] applied by [`Renderer::styled`]
95        pub const DEFAULT_CONTEXT_STYLE: Style = BRIGHT_BLUE.effects(Effects::BOLD);
96        /// [`Renderer::addition`] applied by [`Renderer::styled`]
97        pub const DEFAULT_ADDITION_STYLE: Style = AnsiColor::BrightGreen.on_default();
98        /// [`Renderer::removal`] applied by [`Renderer::styled`]
99        pub const DEFAULT_REMOVAL_STYLE: Style = AnsiColor::BrightRed.on_default();
100    }
101}