1use super::colour::{Colour, COLOUR_DEFAULT};
4
5#[allow(non_snake_case, non_upper_case_globals)]
7pub mod GridAttr {
8 pub const BRIGHT: u16 = 0x1;
10 pub const DIM: u16 = 0x2;
12 pub const UNDERSCORE: u16 = 0x4;
14 pub const BLINK: u16 = 0x8;
16 pub const REVERSE: u16 = 0x10;
18 pub const HIDDEN: u16 = 0x20;
20 pub const ITALICS: u16 = 0x40;
22 pub const CHARSET: u16 = 0x80;
24 pub const STRIKETHROUGH: u16 = 0x100;
26 pub const UNDERSCORE_2: u16 = 0x200;
28 pub const UNDERSCORE_3: u16 = 0x400;
30 pub const UNDERSCORE_4: u16 = 0x800;
32 pub const UNDERSCORE_5: u16 = 0x1000;
34 pub const OVERLINE: u16 = 0x2000;
36 pub const NOATTR: u16 = 0x4000;
38
39 pub const ALL_UNDERSCORE: u16 =
41 UNDERSCORE | UNDERSCORE_2 | UNDERSCORE_3 | UNDERSCORE_4 | UNDERSCORE_5;
42}
43
44#[derive(Debug, Clone, PartialEq, Eq)]
46pub(crate) struct GridCell {
47 pub attr: u16,
48 pub fg: Colour,
49 pub bg: Colour,
50 pub us: Colour,
51 pub link: u32,
52}
53
54impl Default for GridCell {
55 fn default() -> Self {
56 Self {
57 attr: 0,
58 fg: COLOUR_DEFAULT,
59 bg: COLOUR_DEFAULT,
60 us: COLOUR_DEFAULT,
61 link: 0,
62 }
63 }
64}
65
66#[derive(Debug, Clone, Default, PartialEq, Eq)]
68pub struct CellState {
69 pub(crate) cell: GridCell,
71 pub set: i32,
73 pub g0set: i32,
75 pub g1set: i32,
77}
78
79impl CellState {
80 #[must_use]
82 pub fn fg(&self) -> Colour {
83 self.cell.fg
84 }
85
86 #[must_use]
88 pub fn bg(&self) -> Colour {
89 self.cell.bg
90 }
91
92 #[must_use]
94 pub fn us(&self) -> Colour {
95 self.cell.us
96 }
97
98 #[must_use]
100 pub fn attr(&self) -> u16 {
101 self.cell.attr
102 }
103
104 #[must_use]
106 pub fn link(&self) -> u32 {
107 self.cell.link
108 }
109
110 pub(crate) fn reset(&mut self) {
111 self.cell = GridCell::default();
112 self.set = 0;
113 self.g0set = 0;
114 self.g1set = 0;
115 }
116}
117
118#[derive(Debug, Clone, Default, PartialEq, Eq)]
120pub struct SavedState {
121 pub(crate) cell: CellState,
122 pub(crate) cx: u32,
123 pub(crate) cy: u32,
124 pub(crate) mode_origin: bool,
125}
126
127impl SavedState {
128 #[must_use]
130 pub const fn cell(&self) -> &CellState {
131 &self.cell
132 }
133
134 #[must_use]
136 pub const fn cursor_position(&self) -> (u32, u32) {
137 (self.cx, self.cy)
138 }
139
140 #[must_use]
142 pub const fn origin_mode(&self) -> bool {
143 self.mode_origin
144 }
145}