modularize eval
Some checks failed
/ build (push) Has been cancelled

This commit is contained in:
facile pop culture reference 2026-08-02 15:18:56 +03:00
parent 64c83b5460
commit eb028c85fc
12 changed files with 322 additions and 216 deletions

View file

@ -26,28 +26,41 @@ tui_view!(self: State {
let widget = draw(move|to: &mut Tui|self.interpret(to, &src)); // FIXME this forcefills
let sidebar = bg(Color::Rgb(20, 20, 20), north(code, title)).max_w(40);
let content = bg(Color::Rgb(64, 64, 64), widget);
east(sidebar, content)
east(sidebar, ShowSizeOf(content))
//self.size.of(bg(Color::Rgb(10, 10, 10), south(east(sidebar, content), code)).full_w())
//self.size.of(bg(Color::Rgb(10, 10, 10), east(sidebar, content)).full_w())
});
impl_keywords!(Tui, XYWH<u16>, State [
kw_when,
kw_either,
kw_split,
kw_align,
kw_exact,
kw_fixed,
kw_min,
kw_max,
kw_push,
kw_tui_text,
kw_tui_fg,
kw_tui_bg
]);
impl Interpret<Tui, Option<XYWH<u16>>> for State {
fn interpret_word (&self, to: &mut Tui, sym: &impl Language) -> Perhaps<XYWH<u16>> {
match sym.src()? {
Some(":foo") => "foo".draw(to),
Some(":bar") => "bar".draw(to),
Some(":foobar") => "FOOBAR".draw(to),
_ => todo!()
src => todo!("src: {src:?}")
}
}
fn interpret_expr (&self, to: &mut Tui, src: &impl Expression) -> Perhaps<XYWH<u16>> {
Ok(Some(if let Some(area) = eval_view(self, to, src)? {
area
} else if let Some(area) = Tui::eval_view(self, to, src)? {
area
if let Some(area) = self.keyword(to, src)? {
Ok(Some(area))
} else {
return Err(format!("App::interpret_expr: unexpected: {src:?}").into())
}))
Err(format!("App::interpret_expr: unexpected: {src:?}").into())
}
}
}
@ -89,7 +102,7 @@ const VIEWS: &'static [&'static str] = &[
stringify! { :foobar },
stringify! { (text FOOBAR) },
stringify! { (bg (g 8) :foobar) },
stringify! { (fill/xy :foobar) },
//stringify! { (fill/xy :foobar) },
stringify! { (bsp/s (text foo) (text bar)) },
stringify! { (bsp/s :foo :bar) },
stringify! { (bsp/s (bg (g 16) :foo) (bg (g 32) :bar)) },