view* -> understand*

This commit is contained in:
same mf who else 2026-02-21 18:21:50 +02:00
parent b294f2e62b
commit 006cddcc16

View file

@ -80,10 +80,10 @@ pub(crate) use ::std::{
/// FIXME: This is generic: should be called `eval` and be part of [dizzle]. /// FIXME: This is generic: should be called `eval` and be part of [dizzle].
#[cfg(feature = "dsl")] #[macro_export] macro_rules! view { #[cfg(feature = "dsl")] #[macro_export] macro_rules! view {
($State:ident: $Output:ident: $namespaces:expr) => { ($State:ident: $Output:ident: $namespaces:expr) => {
impl View<$Output, ()> for $State { impl Understand<$Output, ()> for $State {
fn view_expr <'a> (&'a self, to: &mut $Output, expr: &'a impl Expression) -> Usually<()> { fn understand_expr <'a> (&'a self, to: &mut $Output, expr: &'a impl Expression) -> Usually<()> {
for namespace in $namespaces { if namespace(self, to, expr)? { return Ok(()) } } for namespace in $namespaces { if namespace(self, to, expr)? { return Ok(()) } }
Err(format!("{}::<{}, ()>::view_expr: unexpected: {expr:?}", Err(format!("{}::<{}, ()>::understand_expr: unexpected: {expr:?}",
stringify! { $State }, stringify! { $State },
stringify! { $Output }).into()) stringify! { $Output }).into())
} }
@ -129,18 +129,18 @@ pub(crate) use ::std::{
Some("when") => output.place(&When::new( Some("when") => output.place(&When::new(
state.namespace(arg0?)?.unwrap(), state.namespace(arg0?)?.unwrap(),
Thunk::new(move|output: &mut O|state.view(output, &arg1).unwrap()) Thunk::new(move|output: &mut O|state.understand(output, &arg1).unwrap())
)), )),
Some("either") => output.place(&Either::new( Some("either") => output.place(&Either::new(
state.namespace(arg0?)?.unwrap(), state.namespace(arg0?)?.unwrap(),
Thunk::new(move|output: &mut O|state.view(output, &arg1).unwrap()), Thunk::new(move|output: &mut O|state.understand(output, &arg1).unwrap()),
Thunk::new(move|output: &mut O|state.view(output, &arg2).unwrap()) Thunk::new(move|output: &mut O|state.understand(output, &arg2).unwrap())
)), )),
Some("bsp") => output.place(&{ Some("bsp") => output.place(&{
let a = Thunk::new(move|output: &mut O|state.view(output, &arg0).unwrap()); let a = Thunk::new(move|output: &mut O|state.understand(output, &arg0).unwrap());
let b = Thunk::new(move|output: &mut O|state.view(output, &arg1).unwrap()); let b = Thunk::new(move|output: &mut O|state.understand(output, &arg1).unwrap());
match frags.next() { match frags.next() {
Some("n") => Bsp::n(a, b), Some("n") => Bsp::n(a, b),
Some("s") => Bsp::s(a, b), Some("s") => Bsp::s(a, b),
@ -153,7 +153,7 @@ pub(crate) use ::std::{
}), }),
Some("align") => output.place(&{ Some("align") => output.place(&{
let a = Thunk::new(move|output: &mut O|state.view(output, &arg0).unwrap()); let a = Thunk::new(move|output: &mut O|state.understand(output, &arg0).unwrap());
match frags.next() { match frags.next() {
Some("n") => Align::n(a), Some("n") => Align::n(a),
Some("s") => Align::s(a), Some("s") => Align::s(a),
@ -167,7 +167,7 @@ pub(crate) use ::std::{
}), }),
Some("fill") => output.place(&{ Some("fill") => output.place(&{
let a = Thunk::new(move|output: &mut O|state.view(output, &arg0).unwrap()); let a = Thunk::new(move|output: &mut O|state.understand(output, &arg0).unwrap());
match frags.next() { match frags.next() {
Some("xy") | None => Fill::XY(a), Some("xy") | None => Fill::XY(a),
Some("x") => Fill::X(a), Some("x") => Fill::X(a),
@ -179,7 +179,7 @@ pub(crate) use ::std::{
Some("fixed") => output.place(&{ Some("fixed") => output.place(&{
let axis = frags.next(); let axis = frags.next();
let arg = match axis { Some("x") | Some("y") => arg1, Some("xy") | None => arg2, _ => panic!("fixed: unsupported axis {axis:?}") }; let arg = match axis { Some("x") | Some("y") => arg1, Some("xy") | None => arg2, _ => panic!("fixed: unsupported axis {axis:?}") };
let cb = Thunk::new(move|output: &mut O|state.view(output, &arg).unwrap()); let cb = Thunk::new(move|output: &mut O|state.understand(output, &arg).unwrap());
match axis { match axis {
Some("xy") | None => Fixed::XY(state.namespace(arg0?)?.unwrap(), state.namespace(arg1?)?.unwrap(), cb), Some("xy") | None => Fixed::XY(state.namespace(arg0?)?.unwrap(), state.namespace(arg1?)?.unwrap(), cb),
Some("x") => Fixed::X(state.namespace(arg0?)?.unwrap(), cb), Some("x") => Fixed::X(state.namespace(arg0?)?.unwrap(), cb),
@ -192,7 +192,7 @@ pub(crate) use ::std::{
Some("min") => output.place(&{ Some("min") => output.place(&{
let axis = frags.next(); let axis = frags.next();
let arg = match axis { Some("x") | Some("y") => arg1, Some("xy") | None => arg2, _ => panic!("fixed: unsupported axis {axis:?}") }; let arg = match axis { Some("x") | Some("y") => arg1, Some("xy") | None => arg2, _ => panic!("fixed: unsupported axis {axis:?}") };
let cb = Thunk::new(move|output: &mut O|state.view(output, &arg).unwrap()); let cb = Thunk::new(move|output: &mut O|state.understand(output, &arg).unwrap());
match axis { match axis {
Some("xy") | None => Min::XY(state.namespace(arg0?)?.unwrap(), state.namespace(arg1?)?.unwrap(), cb), Some("xy") | None => Min::XY(state.namespace(arg0?)?.unwrap(), state.namespace(arg1?)?.unwrap(), cb),
Some("x") => Min::X(state.namespace(arg0?)?.unwrap(), cb), Some("x") => Min::X(state.namespace(arg0?)?.unwrap(), cb),
@ -204,7 +204,7 @@ pub(crate) use ::std::{
Some("max") => output.place(&{ Some("max") => output.place(&{
let axis = frags.next(); let axis = frags.next();
let arg = match axis { Some("x") | Some("y") => arg1, Some("xy") | None => arg2, _ => panic!("fixed: unsupported axis {axis:?}") }; let arg = match axis { Some("x") | Some("y") => arg1, Some("xy") | None => arg2, _ => panic!("fixed: unsupported axis {axis:?}") };
let cb = Thunk::new(move|output: &mut O|state.view(output, &arg).unwrap()); let cb = Thunk::new(move|output: &mut O|state.understand(output, &arg).unwrap());
match axis { match axis {
Some("xy") | None => Max::XY(state.namespace(arg0?)?.unwrap(), state.namespace(arg1?)?.unwrap(), cb), Some("xy") | None => Max::XY(state.namespace(arg0?)?.unwrap(), state.namespace(arg1?)?.unwrap(), cb),
Some("x") => Max::X(state.namespace(arg0?)?.unwrap(), cb), Some("x") => Max::X(state.namespace(arg0?)?.unwrap(), cb),
@ -216,7 +216,7 @@ pub(crate) use ::std::{
Some("push") => output.place(&{ Some("push") => output.place(&{
let axis = frags.next(); let axis = frags.next();
let arg = match axis { Some("x") | Some("y") => arg1, Some("xy") | None => arg2, _ => panic!("fixed: unsupported axis {axis:?}") }; let arg = match axis { Some("x") | Some("y") => arg1, Some("xy") | None => arg2, _ => panic!("fixed: unsupported axis {axis:?}") };
let cb = Thunk::new(move|output: &mut O|state.view(output, &arg).unwrap()); let cb = Thunk::new(move|output: &mut O|state.understand(output, &arg).unwrap());
match axis { match axis {
Some("xy") | None => Push::XY(state.namespace(arg0?)?.unwrap(), state.namespace(arg1?)?.unwrap(), cb), Some("xy") | None => Push::XY(state.namespace(arg0?)?.unwrap(), state.namespace(arg1?)?.unwrap(), cb),
Some("x") => Push::X(state.namespace(arg0?)?.unwrap(), cb), Some("x") => Push::X(state.namespace(arg0?)?.unwrap(), cb),
@ -478,7 +478,7 @@ pub fn tui_input <T: Handle<TuiIn> + Send + Sync + 'static> (
let arg0 = arg0?.expect("fg: expected arg 0 (color)"); let arg0 = arg0?.expect("fg: expected arg 0 (color)");
output.place(&Tui::fg( output.place(&Tui::fg(
Namespace::<Color>::namespace(state, arg0)?.unwrap_or_else(||panic!("fg: {arg0:?}: not a color")), Namespace::<Color>::namespace(state, arg0)?.unwrap_or_else(||panic!("fg: {arg0:?}: not a color")),
Thunk::new(move|output: &mut TuiOut|state.view(output, &arg1).unwrap()), Thunk::new(move|output: &mut TuiOut|state.understand(output, &arg1).unwrap()),
)) ))
}, },
@ -486,7 +486,7 @@ pub fn tui_input <T: Handle<TuiIn> + Send + Sync + 'static> (
let arg0 = arg0?.expect("bg: expected arg 0 (color)"); let arg0 = arg0?.expect("bg: expected arg 0 (color)");
output.place(&Tui::bg( output.place(&Tui::bg(
Namespace::<Color>::namespace(state, arg0)?.unwrap_or_else(||panic!("bg: {arg0:?}: not a color")), Namespace::<Color>::namespace(state, arg0)?.unwrap_or_else(||panic!("bg: {arg0:?}: not a color")),
Thunk::new(move|output: &mut TuiOut|state.view(output, &arg1).unwrap()), Thunk::new(move|output: &mut TuiOut|state.understand(output, &arg1).unwrap()),
)) ))
}, },