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(); } }