mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 11:46:42 +01:00
This commit is contained in:
parent
104bb1c8e7
commit
b52c1f5828
2 changed files with 26 additions and 1 deletions
24
tui/src/tui_content/tui_error.rs
Normal file
24
tui/src/tui_content/tui_error.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
use crate::*;
|
||||
use ratatui::style::Stylize;
|
||||
|
||||
// Thunks can be natural error boundaries!
|
||||
pub struct ErrorBoundary<O: Output, T: Content<O>>(std::marker::PhantomData<O>, Perhaps<T>);
|
||||
|
||||
impl<O: Output, T: Content<O>> ErrorBoundary<O, T> {
|
||||
pub fn new (content: Perhaps<T>) -> Self {
|
||||
Self(Default::default(), content)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Content<TuiOut>> Content<TuiOut> for ErrorBoundary<TuiOut, T> {
|
||||
fn content (&self) -> impl Render<TuiOut> + '_ {
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue