use crate::{NotEnoughSpace, TermColor};
#[doc = crate::_tags!(term data_structure error)]
#[doc = crate::_doc_meta!{location("sys/os/term/grid")}]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum TermGridError {
ExtentOverflow,
NotEnoughElements {
required: usize,
available: usize,
},
RenderSpace(NotEnoughSpace),
RenderPositionOverflow,
UnresolvedColor {
foreground: bool,
color: TermColor,
},
}
crate::impl_trait! {
fmt::Display+Error for TermGridError |self, f| match self {
Self::ExtentOverflow => f.write_str("TermGrid extent overflows the index representation"),
Self::NotEnoughElements { required, available } =>
write!(f, "TermGrid requires {required} elements, but only {available} are available"),
Self::RenderSpace(err) => write!(f, "insufficient terminal renderer space: {err}"),
Self::RenderPositionOverflow =>
f.write_str("positioned TermGrid exceeds the terminal coordinate representation"),
Self::UnresolvedColor { foreground: fg, color } => {
if *fg { write!(f, "TermGrid rendering can't resolve the foreground {color:?}") }
else { write!(f, "TermGrid rendering can't resolve the background {color:?}") }
}
}
}
impl TermGridError {
pub const fn not_enough_elements(required: usize, available: usize) -> Self {
Self::NotEnoughElements { required, available }
}
pub const fn unresolved_color(foreground: bool, color: TermColor) -> Self {
Self::UnresolvedColor { foreground, color }
}
}
impl From<NotEnoughSpace> for TermGridError {
fn from(err: NotEnoughSpace) -> TermGridError {
Self::RenderSpace(err)
}
}