use crate::console::{Console, Renderable};
use crate::text::Text;
use std::sync::Arc;
#[allow(clippy::large_enum_variant)]
#[derive(Clone)]
pub enum CellContent {
Plain(String),
Styled(Text),
Renderable(Arc<dyn Renderable + Send + Sync>),
}
impl std::fmt::Debug for CellContent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
CellContent::Plain(s) => f.debug_tuple("Plain").field(s).finish(),
CellContent::Styled(t) => f.debug_tuple("Styled").field(t).finish(),
CellContent::Renderable(_) => f.write_str("Renderable(<dyn Renderable>)"),
}
}
}
impl CellContent {
pub(crate) fn resolve(&self, console: &Console) -> Text {
match self {
CellContent::Plain(s) => console.render_str(s, None, None, None),
CellContent::Styled(t) => t.clone(),
CellContent::Renderable(r) => {
let segs = console.render(r.as_ref(), None);
let mut t = Text::empty();
for seg in &segs {
t.append_str(&seg.text, seg.style().cloned());
}
t
}
}
}
}
impl From<&str> for CellContent {
fn from(s: &str) -> Self {
CellContent::Plain(s.to_string())
}
}
impl From<String> for CellContent {
fn from(s: String) -> Self {
CellContent::Plain(s)
}
}
impl From<Text> for CellContent {
fn from(t: Text) -> Self {
CellContent::Styled(t)
}
}
impl PartialEq<&str> for CellContent {
fn eq(&self, other: &&str) -> bool {
match self {
CellContent::Plain(s) => s == *other,
CellContent::Styled(t) => t.plain() == *other,
CellContent::Renderable(_) => false,
}
}
}
#[derive(Debug, Clone, Default)]
pub struct Row {
pub style: Option<String>,
pub end_section: bool,
}