use std::ops::{Index, IndexMut}; use crate::vte::ansi::{NamedColor, Rgb}; /// Number of terminal colors. pub const COUNT: usize = 269; /// Array of indexed colors. /// /// | Indices | Description | /// | -------- | ----------------- | /// | 0..16 | Named ANSI colors | /// | 16..232 | Color cube | /// | 233..256 | Grayscale ramp | /// | 256 | Foreground | /// | 257 | Background | /// | 258 | Cursor | /// | 259..267 | Dim colors | /// | 267 | Bright foreground | /// | 268 | Dim background | #[derive(Copy, Clone)] pub struct Colors([Option; COUNT]); impl Default for Colors { fn default() -> Self { Self([None; COUNT]) } } impl Index for Colors { type Output = Option; #[inline] fn index(&self, index: usize) -> &Self::Output { &self.0[index] } } impl IndexMut for Colors { #[inline] fn index_mut(&mut self, index: usize) -> &mut Self::Output { &mut self.0[index] } } impl Index for Colors { type Output = Option; #[inline] fn index(&self, index: NamedColor) -> &Self::Output { &self.0[index as usize] } } impl IndexMut for Colors { #[inline] fn index_mut(&mut self, index: NamedColor) -> &mut Self::Output { &mut self.0[index as usize] } }