pub struct ThemePalette { /* private fields */ }Expand description
A set of 8 anchor colors that define a theme-relative color space.
The 8 anchors map to the standard ANSI color positions:
| Index | Color | Cube corner |
|---|---|---|
| 0 | black | (0, 0, 0) |
| 1 | red | (1, 0, 0) |
| 2 | green | (0, 1, 0) |
| 3 | yellow | (1, 1, 0) |
| 4 | blue | (0, 0, 1) |
| 5 | magenta | (1, 0, 1) |
| 6 | cyan | (0, 1, 1) |
| 7 | white | (1, 1, 1) |
Optional background/foreground overrides let the bg/fg differ from the theme’s black/white (e.g., Solarized where bg is a dark teal, not black).
Implementations§
Source§impl ThemePalette
impl ThemePalette
Sourcepub fn default_xterm() -> Self
pub fn default_xterm() -> Self
Creates a palette using the standard xterm base16 colors.
This is the default when no explicit theme palette is configured.
Sourcepub fn new(anchors: [Rgb; 8]) -> Self
pub fn new(anchors: [Rgb; 8]) -> Self
Creates a new palette from the 8 base ANSI colors.
The array order must be: black, red, green, yellow, blue, magenta, cyan, white.
Background defaults to anchors[0] (black) and foreground to anchors[7] (white).
Sourcepub fn with_bg(self, bg: Rgb) -> Self
pub fn with_bg(self, bg: Rgb) -> Self
Overrides the background color used for the (0,0,0) cube corner.
Useful for themes where the terminal background differs from ANSI black
(e.g., Solarized Dark uses #002b36).
Sourcepub fn with_fg(self, fg: Rgb) -> Self
pub fn with_fg(self, fg: Rgb) -> Self
Overrides the foreground color used for the (1,1,1) cube corner.
Useful for themes where the terminal foreground differs from ANSI white
(e.g., Solarized Dark uses #fdf6e3).
Sourcepub fn resolve(&self, coord: &CubeCoord) -> Rgb
pub fn resolve(&self, coord: &CubeCoord) -> Rgb
Resolves a CubeCoord to an actual RGB color via trilinear LAB interpolation.
This is the core operation: given a position in the theme cube, compute the perceptually interpolated color between the 8 anchor corners.
Sourcepub fn generate_palette(&self, subdivisions: u8) -> Vec<Rgb>
pub fn generate_palette(&self, subdivisions: u8) -> Vec<Rgb>
Generates the extended color palette by subdividing the theme cube.
Returns a Vec<Rgb> containing:
subdivisions³colors from the cube (e.g., 216 for subdivisions=6)- 24 grayscale colors interpolated from background to foreground
The total is subdivisions³ + 24 colors. For subdivisions=6, this gives
the 240 extended colors that fill indices 16–255 of a 256-color palette.
Trait Implementations§
Source§impl Clone for ThemePalette
impl Clone for ThemePalette
Source§fn clone(&self) -> ThemePalette
fn clone(&self) -> ThemePalette
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more