Upload spectral-core/src/cell.rs
Browse files- spectral-core/src/cell.rs +54 -0
spectral-core/src/cell.rs
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
use bitflags::bitflags;
|
| 2 |
+
|
| 3 |
+
/// A single terminal cell.
|
| 4 |
+
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
| 5 |
+
pub struct Cell {
|
| 6 |
+
/// Unicode scalar value or special sentinel.
|
| 7 |
+
pub ch: char,
|
| 8 |
+
/// Foreground color.
|
| 9 |
+
pub fg: u32,
|
| 10 |
+
/// Background color.
|
| 11 |
+
pub bg: u32,
|
| 12 |
+
/// Cell flags (bold, italic, underline, etc.).
|
| 13 |
+
pub flags: CellFlags,
|
| 14 |
+
/// Extra data index (e.g. hyperlink id).
|
| 15 |
+
pub extra: u32,
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
bitflags! {
|
| 19 |
+
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
| 20 |
+
pub struct CellFlags: u16 {
|
| 21 |
+
const BOLD = 0x0001;
|
| 22 |
+
const ITALIC = 0x0002;
|
| 23 |
+
const UNDERLINE = 0x0004;
|
| 24 |
+
const STRIKETHROUGH = 0x0008;
|
| 25 |
+
const WIDE = 0x0010;
|
| 26 |
+
const WIDE_SPACER = 0x0020;
|
| 27 |
+
const COLORED = 0x0040;
|
| 28 |
+
const REVERSE = 0x0080;
|
| 29 |
+
const HIDDEN = 0x0100;
|
| 30 |
+
const BLINK = 0x0200;
|
| 31 |
+
const CURSOR = 0x0400;
|
| 32 |
+
const SELECTED = 0x0800;
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
impl Cell {
|
| 37 |
+
pub fn new(ch: char) -> Self {
|
| 38 |
+
Self {
|
| 39 |
+
ch,
|
| 40 |
+
fg: 0xFF_FFFFFF,
|
| 41 |
+
bg: 0xFF_000000,
|
| 42 |
+
flags: CellFlags::empty(),
|
| 43 |
+
extra: 0,
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
pub fn is_empty(&self) -> bool {
|
| 48 |
+
self.ch == '\0' || self.ch == ' '
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
pub fn reset(&mut self) {
|
| 52 |
+
*self = Self::default();
|
| 53 |
+
}
|
| 54 |
+
}
|