const_colors/
const_colors.rs

1//! Example demonstrating colors in const contexts.
2
3use owo_colors::{colors::*, styles::*, *};
4
5const GREEN_TEXT: FgColorDisplay<Green, str> = FgColorDisplay::new("green text");
6const RED_BG_TEXT: BgColorDisplay<Red, str> = BgColorDisplay::new("red background");
7const COMBO_TEXT: ComboColorDisplay<Blue, White, str> =
8    ComboColorDisplay::new("blue text on white background");
9const DYN_RED_TEXT: FgDynColorDisplay<AnsiColors, str> =
10    FgDynColorDisplay::new("red text (dynamic)", AnsiColors::Red);
11const DYN_GREEN_BG_TEXT: BgDynColorDisplay<AnsiColors, str> =
12    BgDynColorDisplay::new("green background (dynamic)", AnsiColors::Green);
13const COMBO_DYN_TEXT: ComboDynColorDisplay<XtermColors, XtermColors, str> =
14    ComboDynColorDisplay::new(
15        "blue text on lilac background (dynamic)",
16        XtermColors::BlueRibbon,
17        XtermColors::WistfulLilac,
18    );
19
20const BOLD_TEXT: BoldDisplay<str> = BoldDisplay("bold text");
21const DIM_TEXT: DimDisplay<str> = DimDisplay("dim text");
22const ITALIC_TEXT: ItalicDisplay<str> = ItalicDisplay("italic text");
23const UNDERLINE_TEXT: UnderlineDisplay<str> = UnderlineDisplay("underlined text");
24const BLINK_TEXT: BlinkDisplay<str> = BlinkDisplay("blinking text");
25const BLINK_FAST_TEXT: BlinkFastDisplay<str> = BlinkFastDisplay("fast blinking text");
26const REVERSED_TEXT: ReversedDisplay<str> = ReversedDisplay("reversed text");
27const HIDDEN_TEXT: HiddenDisplay<str> = HiddenDisplay("hidden text");
28const STRIKETHROUGH_TEXT: StrikeThroughDisplay<str> = StrikeThroughDisplay("strikethrough text");
29
30const STYLED_TEXT: Styled<&'static str> = Style::new()
31    .bold()
32    .italic()
33    .red()
34    .style("bold and italic red text (dynamically styled)");
35const STYLED_TEXT_2: Styled<&'static str> = Style::new()
36    .effect(Effect::Underline)
37    .effects(&[Effect::Dimmed, Effect::Strikethrough])
38    .green()
39    .style("underlined, dimmed and strikethrough green text (dynamically styled)");
40
41fn main() {
42    println!("{}", GREEN_TEXT);
43    println!("{}", RED_BG_TEXT);
44    println!("{}", COMBO_TEXT);
45    println!("{}", DYN_RED_TEXT);
46    println!("{}", DYN_GREEN_BG_TEXT);
47    println!("{}", COMBO_DYN_TEXT);
48
49    println!("{}", BOLD_TEXT);
50    println!("{}", DIM_TEXT);
51    println!("{}", ITALIC_TEXT);
52    println!("{}", UNDERLINE_TEXT);
53    println!("{}", BLINK_TEXT);
54    println!("{}", BLINK_FAST_TEXT);
55    println!("{}", REVERSED_TEXT);
56    println!("{}", HIDDEN_TEXT);
57    println!("{}", STRIKETHROUGH_TEXT);
58
59    println!("{}", STYLED_TEXT);
60    println!("{}", STYLED_TEXT_2);
61}