still 91 until happiness :(
Some checks failed
/ build (push) Has been cancelled

This commit is contained in:
🪞👃🪞 2025-09-02 22:39:04 +03:00
parent 34070de5f7
commit fd26b12955
18 changed files with 243 additions and 194 deletions

View file

@ -1,97 +1,103 @@
use crate::*;
impl Content<TuiOut> for App {
fn content (&self) -> impl Render<TuiOut> + '_ {
Stack::above(move|add|for dsl in self.mode.view.iter() {
add(&Fill::xy(self.view(dsl.as_ref())));
})
impl Render<TuiOut> for App {
fn render (&self, to: &mut TuiOut) {
to.place(to.area(), &Stack::above(|add|for dsl in self.mode.view.iter() {
add(&self.view(dsl))
}))
}
}
impl App {
fn view <'t, D: Dsl> (&'t self, index: D) -> TuiBox<'t> {
match index.src() {
Ok(Some(src)) => render_dsl(self, src),
Ok(None) => Box::new(Tui::fg(Color::Rgb(192, 192, 192), "empty view")),
Err(e) => Box::new(format!("{e}")),
}
fn view <'a> (&'a self, dsl: impl Dsl + 'a) -> TuiBox<'a> {
self.from(dsl).unwrap().unwrap()
}
pub fn update_clock (&self) {
ViewCache::update_clock(&self.project.clock.view_cache, self.clock(), self.size.w() > 80)
}
}
type TuiBox<'t> = Box<dyn Render<TuiOut> + 't>;
type TuiBox<'a> = Box<dyn Render<TuiOut> + 'a>;
fn render_dsl <'t> (
state: &'t impl DslNs<'t, TuiBox<'t>>,
src: &str
) -> TuiBox<'t> {
let err: Option<Box<dyn Error>> = match state.from(&src) {
Ok(Some(value)) => return value, Ok(None) => None, Err(e) => Some(e),
};
fn render_error (err: impl Error, src: &str) -> impl Render<TuiOut> {
let (fg_1, bg_1) = (Color::Rgb(240, 160, 100), Color::Rgb(48, 0, 0));
let (fg_2, bg_2) = (Color::Rgb(250, 200, 180), Color::Rgb(48, 0, 0));
let (fg_3, bg_3) = (Color::Rgb(250, 200, 120), Color::Rgb(0, 0, 0));
let bg = Color::Rgb(24, 0, 0);
Box::new(col! {
col! {
Tui::fg(bg, Fixed::y(1, Fill::x(RepeatH("")))),
Tui::bg(bg, col! {
Fill::x(Bsp::e(
Tui::bold(true, Tui::fg_bg(fg_1, bg_1, " Render error: ")),
Tui::fg_bg(fg_2, bg_2, err.map(|e|format!(" {e} "))),
Tui::fg_bg(fg_2, bg_2, format!(" {err} ")),
)),
Fill::x(Align::x(Tui::fg_bg(fg_3, bg_3, format!(" {src} ")))),
}),
Tui::fg(bg, Fixed::y(1, Fill::x(RepeatH("")))),
})
}
}
impl<'t> DslNs<'t, TuiBox<'t>> for App {
dsl_exprs!(|app| -> TuiBox<'t> {
"text" (tail: Arc<str>) => Box::new(tail),
impl<'a> DslNs<'a, TuiBox<'a>> for App {}
"fg" (color: Color, x: TuiBox<'t>) => Box::new(Tui::fg(color, x)),
"bg" (color: Color, x: TuiBox<'t>) => Box::new(Tui::bg(color, x)),
"fg/bg" (fg: Color, bg: Color, x: TuiBox<'t>) => Box::new(Tui::fg_bg(fg, bg, x)),
impl<'a> DslNsExprs<'a, TuiBox<'a>> for App {
dsl_exprs!('a |app| -> TuiBox<'a> {
"text" (tail: Arc<str>) => tail.boxed(),
"either" (cond: bool, a: TuiBox<'t>, b: TuiBox<'t>) =>
"fg" (color: Color, x: TuiBox<'a>) => Tui::fg(color, x).boxed(),
"bg" (color: Color, x: TuiBox<'a>) => Tui::bg(color, x).boxed(),
"fg/bg" (fg: Color, bg: Color, x: TuiBox<'a>) => Box::new(Tui::fg_bg(fg, bg, x)),
"either" (cond: bool, a: TuiBox<'a>, b: TuiBox<'a>) =>
Box::new(Either(cond, a, b)),
"bsp/n" (a: TuiBox<'t>, b: TuiBox<'t>) => Box::new(Bsp::n(a, b)),
"bsp/s" (a: TuiBox<'t>, b: TuiBox<'t>) => Box::new(Bsp::s(a, b)),
"bsp/e" (a: TuiBox<'t>, b: TuiBox<'t>) => Box::new(Bsp::e(a, b)),
"bsp/w" (a: TuiBox<'t>, b: TuiBox<'t>) => Box::new(Bsp::w(a, b)),
"bsp/a" (a: TuiBox<'t>, b: TuiBox<'t>) => Box::new(Bsp::a(a, b)),
"bsp/b" (a: TuiBox<'t>, b: TuiBox<'t>) => Box::new(Bsp::b(a, b)),
"bsp/n" (a: TuiBox<'a>, b: TuiBox<'a>) => Box::new(Bsp::n(a, b)),
"bsp/s" (a: TuiBox<'a>, b: TuiBox<'a>) => Box::new(Bsp::s(a, b)),
"bsp/e" (a: TuiBox<'a>, b: TuiBox<'a>) => Box::new(Bsp::e(a, b)),
"bsp/w" (a: TuiBox<'a>, b: TuiBox<'a>) => Box::new(Bsp::w(a, b)),
"bsp/a" (a: TuiBox<'a>, b: TuiBox<'a>) => Box::new(Bsp::a(a, b)),
"bsp/b" (a: TuiBox<'a>, b: TuiBox<'a>) => Box::new(Bsp::b(a, b)),
"align/nw" (x: TuiBox<'t>) => Box::new(Align::nw(x)),
"align/ne" (x: TuiBox<'t>) => Box::new(Align::ne(x)),
"align/n" (x: TuiBox<'t>) => Box::new(Align::n(x)),
"align/s" (x: TuiBox<'t>) => Box::new(Align::s(x)),
"align/e" (x: TuiBox<'t>) => Box::new(Align::e(x)),
"align/w" (x: TuiBox<'t>) => Box::new(Align::w(x)),
"align/x" (x: TuiBox<'t>) => Box::new(Align::x(x)),
"align/y" (x: TuiBox<'t>) => Box::new(Align::y(x)),
"align/c" (x: TuiBox<'t>) => Box::new(Align::c(x)),
"align/nw" (x: TuiBox<'a>) => Box::new(Align::nw(x)),
"align/ne" (x: TuiBox<'a>) => Box::new(Align::ne(x)),
"align/n" (x: TuiBox<'a>) => Box::new(Align::n(x)),
"align/s" (x: TuiBox<'a>) => Box::new(Align::s(x)),
"align/e" (x: TuiBox<'a>) => Box::new(Align::e(x)),
"align/w" (x: TuiBox<'a>) => Box::new(Align::w(x)),
"align/x" (x: TuiBox<'a>) => Box::new(Align::x(x)),
"align/y" (x: TuiBox<'a>) => Box::new(Align::y(x)),
"align/c" (x: TuiBox<'a>) => Box::new(Align::c(x)),
"fill/x" (x: TuiBox<'t>) => Box::new(Fill::x(x)),
"fill/y" (x: TuiBox<'t>) => Box::new(Fill::y(x)),
"fill/xy" (x: TuiBox<'t>) => Box::new(Fill::xy(x)),
"fill/x" (x: TuiBox<'a>) => Box::new(Fill::x(x)),
"fill/y" (x: TuiBox<'a>) => Box::new(Fill::y(x)),
"fill/xy" (x: TuiBox<'a>) => Box::new(Fill::xy(x)),
"fixed/x" (x: u16, c: TuiBox<'t>) => Box::new(Fixed::x(x, c)),
"fixed/y" (y: u16, c: TuiBox<'t>) => Box::new(Fixed::y(y, c)),
"fixed/xy" (x: u16, y: u16, c: TuiBox<'t>) => Box::new(Fixed::xy(x, y, c)),
"fixed/x" (x: u16, c: TuiBox<'a>) => Box::new(Fixed::x(x, c)),
"fixed/y" (y: u16, c: TuiBox<'a>) => Box::new(Fixed::y(y, c)),
"fixed/xy" (x: u16, y: u16, c: TuiBox<'a>) => Box::new(Fixed::xy(x, y, c)),
"min/x" (x: u16, c: TuiBox<'t>) => Box::new(Min::x(x, c)),
"min/y" (y: u16, c: TuiBox<'t>) => Box::new(Min::y(y, c)),
"min/xy" (x: u16, y: u16, c: TuiBox<'t>) => Box::new(Min::xy(x, y, c)),
"min/x" (x: u16, c: TuiBox<'a>) => Box::new(Min::x(x, c)),
"min/y" (y: u16, c: TuiBox<'a>) => Box::new(Min::y(y, c)),
"min/xy" (x: u16, y: u16, c: TuiBox<'a>) => Box::new(Min::xy(x, y, c)),
"max/x" (x: u16, c: TuiBox<'t>) => Box::new(Max::x(x, c)),
"max/y" (y: u16, c: TuiBox<'t>) => Box::new(Max::y(y, c)),
"max/xy" (x: u16, y: u16, c: TuiBox<'t>) => Box::new(Max::xy(x, y, c)),
"max/x" (x: u16, c: TuiBox<'a>) => Box::new(Max::x(x, c)),
"max/y" (y: u16, c: TuiBox<'a>) => Box::new(Max::y(y, c)),
"max/xy" (x: u16, y: u16, c: TuiBox<'a>) => Box::new(Max::xy(x, y, c)),
});
dsl_words!(|app| -> TuiBox<'t> {
/// Resolve an expression if known.
fn from_expr (&'a self, dsl: impl Dsl) -> Perhaps<TuiBox<'a>> {
if let Some(head) = dsl.expr().head()? {
for (key, value) in Self::EXPRS.iter() {
if head == *key {
return value(self, dsl.expr().tail()?.unwrap_or(""))
}
}
}
return Ok(None)
}
}
impl<'a> DslNsWords<'a, TuiBox<'a>> for App {
dsl_words!('a |app| -> TuiBox<'a> {
":logo" => Box::new(Fixed::xy(32, 7, Tui::bold(true, Tui::fg(Rgb(240,200,180), Stack::south(|add|{
add(&Fixed::y(1, ""));
add(&Fixed::y(1, ""));
@ -168,27 +174,14 @@ impl<'t> DslNs<'t, TuiBox<'t>> for App {
let rb = if i == selected { " ]" } else { " " };
Fill::x(Tui::bg(bg, Bsp::e(lb, Bsp::w(rb, "FIXME device name")))) }))) },
});
/// Resolve an expression if known.
fn from_expr <D: Dsl> (&self, dsl: &D) -> Perhaps<TuiBox<'t>> {
if let Some(head) = dsl.expr().head()? {
for (key, value) in Self::EXPRS.0.iter() {
if head == *key {
return value(self, dsl.expr().tail()?.unwrap_or(""))
}
}
}
return Ok(None)
}
/// Resolve a symbol if known.
fn from_word <D: Dsl> (&self, dsl: &D) -> Perhaps<TuiBox<'t>> {
fn from_word (&'a self, dsl: impl Dsl) -> Perhaps<TuiBox<'a>> {
if let Some(dsl) = dsl.word()? {
let views = self.config.views.read().unwrap();
if let Some(view) = views.get(dsl) {
let view = view.clone();
std::mem::drop(views);
return Ok(Some(render_dsl(self, view.as_ref())))
return Ok(Some(self.view(view).boxed()))
}
for (word, get) in Self::WORDS.0 {
for (word, get) in Self::WORDS {
if dsl == *word {
return get(self)
}