retroglyph_core/color/mod.rs
1//! Color and style types for character cells: [`Color`] (this module) and [`Style`], a `{fg,
2//! bg}` pair of two `Color`s with no other relation to anything else in this crate.
3//!
4//! Split into private submodules by concern, `animate`/`backend`/`testing`-style: `ansi` is the
5//! 16-color ANSI palette and the shared indexed/ANSI quantization machinery, `convert` is
6//! `Color`'s inherent methods (constants, RGB resolution, `gem` color-space conversions),
7//! `named` is `Color`'s string-name/hex constructors (`from_named`, `from_hex`), `palette_oklab`
8//! is the generated Oklab table `ansi` quantizes against, `parse` is `Color`'s
9//! `Display`/`FromStr`/serde impls, `style` is [`Style`](crate::color::Style) itself, and `tint`
10//! is [`Tint`](crate::color::Tint), sprite colour modulation.
11
12mod ansi;
13mod convert;
14mod named;
15mod palette_oklab;
16mod parse;
17mod style;
18mod tint;
19
20pub use ansi::{AnsiColor, InvalidAnsiIndex, Quantize};
21pub use parse::ParseColorError;
22pub use style::Style;
23pub use tint::Tint;
24
25#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
26#[non_exhaustive]
27/// Represents a color in the terminal grid.
28///
29/// # Examples
30///
31/// ```
32/// use retroglyph_core::color::Color;
33///
34/// let named = Color::GREEN;
35/// let rgb = Color::Rgb { r: 255, g: 0, b: 0 };
36/// let indexed = Color::Indexed(42);
37/// assert_ne!(named, rgb);
38/// assert_ne!(rgb, indexed);
39/// ```
40pub enum Color {
41 #[default]
42 /// Backend's default foreground/background color.
43 ///
44 /// This tells the rendering backend to use the terminal's configured
45 /// default colors (e.g., the user's background color preference).
46 Default,
47 /// One of the 16 standard ANSI colors.
48 ///
49 /// Use these to respect the user's terminal theme.
50 Ansi(AnsiColor),
51 /// 256-color palette index.
52 Indexed(u8),
53 /// 24-bit RGB color.
54 ///
55 /// Use this for exact color matching regardless of terminal settings.
56 Rgb {
57 /// Red channel.
58 r: u8,
59 /// Green channel.
60 g: u8,
61 /// Blue channel.
62 b: u8,
63 },
64}