almost back in commission

This commit is contained in:
🪞👃🪞 2025-08-23 12:19:35 +03:00
parent fa5f67f010
commit d5865d941f
7 changed files with 219 additions and 216 deletions

View file

@ -2,17 +2,21 @@ use crate::*;
impl<'t> DslNs<'t, Box<dyn Render<TuiOut>>> for App {
dsl_exprs!(|app| -> Box<dyn Render<TuiOut>> {
"fg" (color: Color, x: Box<dyn Render<TuiOut>>) => Box::new(Tui::fg(color, x)),
"bg" (color: Color, x: Box<dyn Render<TuiOut>>) => Box::new(Tui::bg(color, x)),
"fg/bg" (fg: Color, bg: Color, x: Box<dyn Render<TuiOut>>) => Box::new(Tui::fg_bg(fg, bg, x)),
"text" (tail: Arc<str>) => Box::new(tail),
"bsp/n" (a: Box<dyn Render<TuiOut>>, b: Box<dyn Render<TuiOut>>) => Box::new(Bsp::n(a, b)),
"bsp/s" (a: Box<dyn Render<TuiOut>>, b: Box<dyn Render<TuiOut>>) => Box::new(Bsp::s(a, b)),
"bsp/e" (a: Box<dyn Render<TuiOut>>, b: Box<dyn Render<TuiOut>>) => Box::new(Bsp::e(a, b)),
"bsp/w" (a: Box<dyn Render<TuiOut>>, b: Box<dyn Render<TuiOut>>) => Box::new(Bsp::w(a, b)),
"bsp/a" (a: Box<dyn Render<TuiOut>>, b: Box<dyn Render<TuiOut>>) => Box::new(Bsp::a(a, b)),
"bsp/b" (a: Box<dyn Render<TuiOut>>, b: Box<dyn Render<TuiOut>>) => Box::new(Bsp::b(a, b)),
"fg" (color: Color, x: Box<dyn Render<TuiOut>>) => Box::new(Tui::fg(color, x)),
"bg" (color: Color, x: Box<dyn Render<TuiOut>>) => Box::new(Tui::bg(color, x)),
"fg/bg" (fg: Color, bg: Color, x: Box<dyn Render<TuiOut>>) => Box::new(Tui::fg_bg(fg, bg, x)),
"bsp/n" (a: Box<dyn Render<TuiOut>>, b: Box<dyn Render<TuiOut>>) => Box::new(Bsp::n(a, b)),
"bsp/s" (a: Box<dyn Render<TuiOut>>, b: Box<dyn Render<TuiOut>>) => Box::new(Bsp::s(a, b)),
"bsp/e" (a: Box<dyn Render<TuiOut>>, b: Box<dyn Render<TuiOut>>) => Box::new(Bsp::e(a, b)),
"bsp/w" (a: Box<dyn Render<TuiOut>>, b: Box<dyn Render<TuiOut>>) => Box::new(Bsp::w(a, b)),
"bsp/a" (a: Box<dyn Render<TuiOut>>, b: Box<dyn Render<TuiOut>>) => Box::new(Bsp::a(a, b)),
"bsp/b" (a: Box<dyn Render<TuiOut>>, b: Box<dyn Render<TuiOut>>) => Box::new(Bsp::b(a, b)),
"align/nw" (x: Box<dyn Render<TuiOut>>) => Box::new(Align::nw(x)),
"align/ne" (x: Box<dyn Render<TuiOut>>) => Box::new(Align::ne(x)),
"align/n" (x: Box<dyn Render<TuiOut>>) => Box::new(Align::n(x)),
"align/s" (x: Box<dyn Render<TuiOut>>) => Box::new(Align::s(x)),
"align/e" (x: Box<dyn Render<TuiOut>>) => Box::new(Align::e(x)),
@ -21,43 +25,46 @@ impl<'t> DslNs<'t, Box<dyn Render<TuiOut>>> for App {
"align/y" (x: Box<dyn Render<TuiOut>>) => Box::new(Align::y(x)),
"align/c" (x: Box<dyn Render<TuiOut>>) => Box::new(Align::c(x)),
"fill/x" (x: Box<dyn Render<TuiOut>>) => Box::new(Fill::x(x)),
"fill/y" (x: Box<dyn Render<TuiOut>>) => Box::new(Fill::y(x)),
"fill/xy" (x: Box<dyn Render<TuiOut>>) => Box::new(Fill::xy(x)),
"fill/x" (x: Box<dyn Render<TuiOut>>) => Box::new(Fill::x(x)),
"fill/y" (x: Box<dyn Render<TuiOut>>) => Box::new(Fill::y(x)),
"fill/xy" (x: Box<dyn Render<TuiOut>>) => Box::new(Fill::xy(x)),
"fixed/x" (x: u16, c: Box<dyn Render<TuiOut>>) => Box::new(Fixed::x(x, c)),
"fixed/y" (y: u16, c: Box<dyn Render<TuiOut>>) => Box::new(Fixed::y(y, c)),
"fixed/xy" (x: u16, y: u16, c: Box<dyn Render<TuiOut>>) => Box::new(Fixed::xy(x, y, c)),
"min/x" (x: u16, c: Box<dyn Render<TuiOut>>) => Box::new(Min::x(x, c)),
"min/y" (y: u16, c: Box<dyn Render<TuiOut>>) => Box::new(Min::y(y, c)),
"min/xy" (x: u16, y: u16, c: Box<dyn Render<TuiOut>>) => Box::new(Min::xy(x, y, c)),
"min/x" (x: u16, c: Box<dyn Render<TuiOut>>) => Box::new(Min::x(x, c)),
"min/y" (y: u16, c: Box<dyn Render<TuiOut>>) => Box::new(Min::y(y, c)),
"min/xy" (x: u16, y: u16, c: Box<dyn Render<TuiOut>>) => Box::new(Min::xy(x, y, c)),
"max/x" (x: u16, c: Box<dyn Render<TuiOut>>) => Box::new(Max::x(x, c)),
"max/y" (y: u16, c: Box<dyn Render<TuiOut>>) => Box::new(Max::y(y, c)),
"max/xy" (x: u16, y: u16, c: Box<dyn Render<TuiOut>>) => Box::new(Max::xy(x, y, c)),
"max/x" (x: u16, c: Box<dyn Render<TuiOut>>) => Box::new(Max::x(x, c)),
"max/y" (y: u16, c: Box<dyn Render<TuiOut>>) => Box::new(Max::y(y, c)),
"max/xy" (x: u16, y: u16, c: Box<dyn Render<TuiOut>>) => Box::new(Max::xy(x, y, c)),
});
dsl_words!(|app| -> Box<dyn Render<TuiOut>> {
":templates" => Box::new({
let modes = app.config.modes.clone();
let height = (modes.read().unwrap().len() * 2) as u16;
Min::x(30, Fixed::y(height, Stack::south(move|add: &mut dyn FnMut(&dyn Render<TuiOut>)|{
Fixed::y(height, Min::x(30, Stack::south(move|add: &mut dyn FnMut(&dyn Render<TuiOut>)|{
for (index, (id, profile)) in modes.read().unwrap().iter().enumerate() {
let bg = if index == 0 { Rgb(48,64,32) } else { Rgb(16, 32, 24) };
let bg = if index == 0 { Rgb(70,70,70) } else { Rgb(50,50,50) };
let name = profile.name.get(0).map(|x|x.as_ref()).unwrap_or("<no name>");
let info = profile.info.get(0).map(|x|x.as_ref()).unwrap_or("<no info>");
let fg1 = Rgb(224, 192, 128);
let fg2 = Rgb(224, 128, 32);
let field_name = Fill::x(Align::w(Tui::fg(fg1, name)));
let field_id = Fill::x(Align::e(Tui::fg(fg2, id)));
let field_info = Fill::x(Align::w(info));
add(&Fixed::y(2, Fill::x(Tui::bg(bg, Bsp::s(
Bsp::a(Fill::x(Align::w(Tui::fg(fg1, name))),
Fill::x(Align::e(Tui::fg(fg2, id)))),
Align::w(info))))));
}})))}),
":sessions" => Box::new(Min::x(30, Fixed::y(6, Stack::south(
Bsp::a(field_name, field_id), field_info)))));
}
})))
}),
":sessions" => Box::new(Fixed::y(6, Min::x(30, Stack::south(
move|add: &mut dyn FnMut(&dyn Render<TuiOut>)|{
let fg = Rgb(224, 192, 128);
for (index, name) in ["session1", "session2", "session3"].iter().enumerate() {
let bg = if index == 0 { Rgb(48,64,32) } else { Rgb(16, 32, 24) };
let bg = if index == 0 { Rgb(50,50,50) } else { Rgb(40,40,40) };
add(&Fixed::y(2, Fill::x(Tui::bg(bg, Align::w(Tui::fg(fg, name))))));
}
}
@ -82,7 +89,7 @@ impl<'t> DslNs<'t, Box<dyn Render<TuiOut>>> for App {
Fill::x(Tui::bg(bg, Bsp::e(lb, Bsp::w(rb, "FIXME device name")))) }))) },
});
/// Resolve an expression if known.
fn from_expr <D: Dsl> (&'t self, dsl: D) -> Perhaps<Box<dyn Render<TuiOut>>> {
fn from_expr <D: Dsl> (&self, dsl: &D) -> Perhaps<Box<dyn Render<TuiOut>>> {
if let Some(head) = dsl.expr().head()? {
for (key, value) in Self::EXPRS.0.iter() {
if head == *key {
@ -93,7 +100,7 @@ impl<'t> DslNs<'t, Box<dyn Render<TuiOut>>> for App {
return Ok(None)
}
/// Resolve a symbol if known.
fn from_word <D: Dsl> (&'t self, dsl: D) -> Perhaps<Box<dyn Render<TuiOut>>> {
fn from_word <D: Dsl> (&self, dsl: &D) -> Perhaps<Box<dyn Render<TuiOut>>> {
if let Some(dsl) = dsl.word()? {
let views = self.config.views.read().unwrap();
if let Some(view) = views.get(dsl) {
@ -101,7 +108,11 @@ impl<'t> DslNs<'t, Box<dyn Render<TuiOut>>> for App {
std::mem::drop(views);
return Ok(Some(render_dsl(self, view.as_ref())))
}
for (word, get) in Self::WORDS.0 { if dsl == *word { return get(self) } }
for (word, get) in Self::WORDS.0 {
if dsl == *word {
return get(self)
}
}
}
return Ok(None)
}