fluent_ansi/colors/basic.rs
1use crate::{
2 colors::{Color, SimpleColor},
3 impl_macros::{color_type::impl_color_type, from_to::impl_from_to},
4};
5
6/// The 8 basic non-bright terminal colors.
7///
8/// These colors are also available as associated constants in the [`Color`](super::Color) enum:
9///
10/// ```
11/// use fluent_ansi::{prelude::*, color::BasicColor};
12///
13/// assert_eq!(Color::RED, BasicColor::Red);
14/// assert_eq!(Color::GREEN, BasicColor::Green);
15/// assert_eq!(Color::BLUE, BasicColor::Blue);
16/// // etc.
17/// ```
18///
19/// See Wikipedia's article on [3-bit and 4-bit colors ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit).
20#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
21pub enum BasicColor {
22 /// The black color.
23 Black,
24 /// The red color.
25 Red,
26 /// The green color.
27 Green,
28 /// The yellow color.
29 Yellow,
30 /// The blue color.
31 Blue,
32 /// The magenta color.
33 Magenta,
34 /// The cyan color.
35 Cyan,
36 /// The white color.
37 White,
38}
39
40impl BasicColor {
41 /// Returns a bright variant of this basic color.
42 #[must_use]
43 pub fn bright(self) -> SimpleColor {
44 SimpleColor::new_bright(self)
45 }
46
47 #[must_use]
48 pub(crate) fn code_offset(self) -> u8 {
49 self as u8
50 }
51}
52
53impl_color_type!(BasicColor {
54 args: [self];
55 to_color: {
56 self.to_simple_color().to_color()
57 }
58});
59
60impl_from_to!(
61 #[doc = r"Convert this basic color into a [`SimpleColor`]."]
62 fn to_simple_color(self: BasicColor) -> SimpleColor {
63 SimpleColor::new(self)
64 }
65);