mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 03:36:41 +01:00
view: ErrorBoundary
This commit is contained in:
parent
e81955890c
commit
8c175e22f5
2 changed files with 22 additions and 27 deletions
|
|
@ -2,37 +2,32 @@ use crate::*;
|
|||
pub(crate) use std::fmt::Write;
|
||||
pub(crate) use ::tengri::tui::ratatui::prelude::Position;
|
||||
|
||||
impl App {
|
||||
pub fn view (&self) -> impl Content<TuiOut> + '_ {
|
||||
let view: Perhaps<Box<dyn Render<TuiOut>>> =
|
||||
Namespace::take_from(self, &mut self.config.view.clone());
|
||||
Either(view.is_ok(),
|
||||
ThunkRender::new(move|to|if let Some(view) = view.as_ref().unwrap().as_ref() {
|
||||
Content::render(view, to)
|
||||
}),
|
||||
"error?!")
|
||||
//Fill::xy(self.size.of(col! {
|
||||
//Tui::bg(Rgb(72,72,0), When(matches!(&view, Err(_)), Bsp::s(
|
||||
//Fixed::y(1, "view error"),
|
||||
//Bsp::s(
|
||||
//view.as_ref().err().map(|e|format!("{e}")),
|
||||
//format!("{}", &self.config.view.0.0))))),
|
||||
//When(matches!(&view, Ok(None)), Bsp::s(
|
||||
//Tui::bg(Rgb(96,48,0),
|
||||
//Fixed::y(1, Fill::x(Align::w("no view returned, as defined by:")))),
|
||||
//Tui::bg(Rgb(72,32,0),
|
||||
//Fill::x(Stack::south(|add: &mut dyn FnMut(&dyn Render<TuiOut>)|{
|
||||
//for line in self.config.view.0.0.split('\n') {
|
||||
//add(&Fill::x(Align::w(line)));
|
||||
//}
|
||||
//}))))),
|
||||
//When(matches!(&view, Ok(Some(_))), &view.unwrap().unwrap()),
|
||||
//}))
|
||||
// Thunks can be natural error boundaries!
|
||||
struct ErrorBoundary<O: Output, T: Content<O>>(std::marker::PhantomData<O>, Perhaps<T>);
|
||||
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(
|
||||
Rgb(255,224,244),
|
||||
Rgb(96,24,24),
|
||||
Bsp::s(
|
||||
Bsp::e(Tui::bold(true, "oops. "), "rendering failed."),
|
||||
Bsp::e("\"why?\" ", Tui::bold(true, &format!("{e}"))),
|
||||
)), to)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[tengri_proc::view(TuiOut)]
|
||||
impl App {
|
||||
pub fn view (app: &Self) -> impl Content<TuiOut> {
|
||||
ErrorBoundary::<TuiOut, Box<dyn Render<TuiOut> + '_>>(
|
||||
Default::default(),
|
||||
Namespace::take_from(app, &mut app.config.view.clone())
|
||||
)
|
||||
}
|
||||
pub fn view_nil (app: &Self) -> impl Content<TuiOut> {
|
||||
"nil"
|
||||
}
|
||||
|
|
|
|||
2
deps/tengri
vendored
2
deps/tengri
vendored
|
|
@ -1 +1 @@
|
|||
Subproject commit 776cea6f1ba502b87bcaed3a7d794076e328df2e
|
||||
Subproject commit 7516517078d71183cfa4c409aa8a6948675ebe7a
|
||||
Loading…
Add table
Add a link
Reference in a new issue