diff --git a/tui/src/tui_content.rs b/tui/src/tui_content.rs index 108d0b2..9fc0c13 100644 --- a/tui/src/tui_content.rs +++ b/tui/src/tui_content.rs @@ -15,10 +15,11 @@ macro_rules! impl_content_layout_render { mod tui_border; pub use self::tui_border::*; mod tui_button; //pub use self::tui_button::*; mod tui_color; pub use self::tui_color::*; +mod tui_error; pub use self::tui_error::*; mod tui_field; pub use self::tui_field::*; +mod tui_number; //pub use self::tui_number::*; mod tui_phat; pub use self::tui_phat::*; mod tui_repeat; pub use self::tui_repeat::*; -mod tui_number; //pub use self::tui_number::*; mod tui_scroll; pub use self::tui_scroll::*; mod tui_string; pub use self::tui_string::*; mod tui_style; pub use self::tui_style::*; diff --git a/tui/src/tui_content/tui_error.rs b/tui/src/tui_content/tui_error.rs new file mode 100644 index 0000000..e48f203 --- /dev/null +++ b/tui/src/tui_content/tui_error.rs @@ -0,0 +1,24 @@ +use crate::*; +use ratatui::style::Stylize; + +// Thunks can be natural error boundaries! +pub struct ErrorBoundary>(std::marker::PhantomData, Perhaps); + +impl> ErrorBoundary { + pub fn new (content: Perhaps) -> Self { + Self(Default::default(), content) + } +} + +impl> Content for ErrorBoundary { + fn content (&self) -> impl Render + '_ { + ThunkRender::new(|to|match self.1.as_ref() { + Ok(Some(content)) => content.render(to), + Ok(None) => to.blit(&"empty?", 0, 0, Some(Style::default().yellow())), + Err(e) => Content::render(&Tui::fg_bg( + Color::Rgb(255,224,244), Color::Rgb(96,24,24), Bsp::s( + Bsp::e(Tui::bold(true, "oops. "), "rendering failed."), + Bsp::e("\"why?\" ", Tui::bold(true, &format!("{e}"))))), to) + }) + } +}