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