use super::colour::{Colour, COLOUR_DEFAULT};
#[allow(non_snake_case, non_upper_case_globals)]
pub mod GridAttr {
pub const BRIGHT: u16 = 0x1;
pub const DIM: u16 = 0x2;
pub const UNDERSCORE: u16 = 0x4;
pub const BLINK: u16 = 0x8;
pub const REVERSE: u16 = 0x10;
pub const HIDDEN: u16 = 0x20;
pub const ITALICS: u16 = 0x40;
pub const CHARSET: u16 = 0x80;
pub const STRIKETHROUGH: u16 = 0x100;
pub const UNDERSCORE_2: u16 = 0x200;
pub const UNDERSCORE_3: u16 = 0x400;
pub const UNDERSCORE_4: u16 = 0x800;
pub const UNDERSCORE_5: u16 = 0x1000;
pub const OVERLINE: u16 = 0x2000;
pub const NOATTR: u16 = 0x4000;
pub const ALL_UNDERSCORE: u16 =
UNDERSCORE | UNDERSCORE_2 | UNDERSCORE_3 | UNDERSCORE_4 | UNDERSCORE_5;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct GridCell {
pub attr: u16,
pub fg: Colour,
pub bg: Colour,
pub us: Colour,
pub link: u32,
}
impl Default for GridCell {
fn default() -> Self {
Self {
attr: 0,
fg: COLOUR_DEFAULT,
bg: COLOUR_DEFAULT,
us: COLOUR_DEFAULT,
link: 0,
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct CellState {
pub(crate) cell: GridCell,
pub set: i32,
pub g0set: i32,
pub g1set: i32,
}
impl CellState {
#[must_use]
pub fn fg(&self) -> Colour {
self.cell.fg
}
#[must_use]
pub fn bg(&self) -> Colour {
self.cell.bg
}
#[must_use]
pub fn us(&self) -> Colour {
self.cell.us
}
#[must_use]
pub fn attr(&self) -> u16 {
self.cell.attr
}
#[must_use]
pub fn link(&self) -> u32 {
self.cell.link
}
pub(crate) fn reset(&mut self) {
self.cell = GridCell::default();
self.set = 0;
self.g0set = 0;
self.g1set = 0;
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct SavedState {
pub(crate) cell: CellState,
pub(crate) cx: u32,
pub(crate) cy: u32,
pub(crate) mode_origin: bool,
}
impl SavedState {
#[must_use]
pub const fn cell(&self) -> &CellState {
&self.cell
}
#[must_use]
pub const fn cursor_position(&self) -> (u32, u32) {
(self.cx, self.cy)
}
#[must_use]
pub const fn origin_mode(&self) -> bool {
self.mode_origin
}
}