use compact_str::CompactString;
use compact_str::ToCompactString;
use crossterm::style::Attributes;
use crossterm::style::Color;
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Cell {
symbol: CompactString,
fg: Color,
bg: Color,
attrs: Attributes,
}
impl Cell {
pub fn symbol(&self) -> &CompactString {
&self.symbol
}
pub fn set_symbol(&mut self, symbol: CompactString) {
self.symbol = symbol;
}
pub fn set_char(&mut self, ch: char) {
self.symbol = ch.to_compact_string();
}
pub fn set_str(&mut self, s: &str) {
self.symbol = CompactString::new(s);
}
pub fn fg(&self) -> &Color {
&self.fg
}
pub fn set_fg(&mut self, color: Color) {
self.fg = color;
}
pub fn bg(&self) -> &Color {
&self.bg
}
pub fn set_bg(&mut self, color: Color) {
self.bg = color;
}
pub fn attrs(&self) -> &Attributes {
&self.attrs
}
pub fn set_attrs(&mut self, value: Attributes) {
self.attrs = value;
}
}
impl Cell {
pub fn new(
symbol: CompactString,
fg: Color,
bg: Color,
attrs: Attributes,
) -> Self {
Cell {
symbol,
fg,
bg,
attrs,
}
}
pub fn space() -> Self {
Cell {
symbol: " ".to_compact_string(),
fg: Color::Reset,
bg: Color::Reset,
attrs: Attributes::default(),
}
}
pub fn empty() -> Self {
Cell {
symbol: CompactString::const_new(""),
fg: Color::Reset,
bg: Color::Reset,
attrs: Attributes::default(),
}
}
pub fn with_char(c: char) -> Self {
Cell {
symbol: c.to_compact_string(),
fg: Color::Reset,
bg: Color::Reset,
attrs: Attributes::default(),
}
}
pub fn with_symbol(s: CompactString) -> Self {
Cell {
symbol: s,
fg: Color::Reset,
bg: Color::Reset,
attrs: Attributes::default(),
}
}
}
impl From<char> for Cell {
fn from(value: char) -> Self {
Cell::new(
value.to_compact_string(),
Color::Reset,
Color::Reset,
Attributes::default(),
)
}
}