reorganize, add Azimuth

This commit is contained in:
facile pop culture reference 2026-07-06 20:40:52 +03:00
parent bf16288884
commit 1f60b43f61
26 changed files with 677 additions and 594 deletions

View file

@ -1,4 +1,5 @@
use crate::{*, term::*, draw::*, space::*, lang::*, ratatui::prelude::*};
use crate::{*, lang::*};
use ratatui::style::Color;
/// Some layout operations exist in XY, X, and Y variants that take 3 or 2 arguments.
/// Their handling in [eval_view] is uniform and goes like this:
@ -78,7 +79,7 @@ macro_rules! eval_enum ((
pub fn eval_view <'a, O: Screen + 'a, S> (
state: &S, output: &mut O, expr: &'a impl Expression
) -> Perhaps<XYWH<O::Unit>> where
S: Interpret<O, XYWH<O::Unit>>
S: Interpret<O, Option<XYWH<O::Unit>>>
+ for<'b> Namespace<'b, bool>
+ for<'b> Namespace<'b, O::Unit>
+ for<'b> Namespace<'b, Option<O::Unit>>
@ -100,35 +101,58 @@ pub fn eval_view <'a, O: Screen + 'a, S> (
let arg2 = tail1.head();
// First `frags.next()` calls returns the namespace.
Some(match frags.next() {
match frags.next() {
Some("when") => when(
state.namespace(arg0?)?.unwrap(),
thunk(move|output: &mut O|state.interpret(output, &arg1))
thunk(move|output: &mut O|{
state.interpret(output, &arg1)
})
).draw(output),
Some("either") => either(
state.namespace(arg0?)?.unwrap(),
thunk(move|output: &mut O|state.interpret(output, &arg1)),
thunk(move|output: &mut O|state.interpret(output, &arg2)),
thunk(move|output: &mut O|{
state.interpret(output, &arg1)
}),
thunk(move|output: &mut O|{
state.interpret(output, &arg2)
}),
).draw(output),
// Second `frags.next()` calls returns the namespace member.
Some("bsp") => {
let direction = eval_enum!("bsp", output, state, frags.next(), arg0, Split {
"n" => North, "s" => South, "e" => East, "w" => West, "a" => Above, "b" => Below
"n" => North,
"s" => South,
"e" => East,
"w" => West,
"a" => Above,
"b" => Below
});
direction.half(
thunk(move|output: &mut O|state.interpret(output, &arg0)),
thunk(move|output: &mut O|state.interpret(output, &arg1)),
thunk(move|output: &mut O|{
state.interpret(output, &arg0)
}),
thunk(move|output: &mut O|{
state.interpret(output, &arg1)
}),
).draw(output)
},
Some("align") => {
let alignment = eval_enum!("align", output, state, frags.next(), arg0, Origin {
"c" => C, "n" => N, "s" => S, "e" => E, "w" => W, "x" => X, "y" => Y
let alignment = eval_enum!("align", output, state, frags.next(), arg0, Azimuth {
"c" => C,
"n" => N,
"s" => S,
"e" => E,
"w" => W,
"x" => X,
"y" => Y
});
let content = thunk(move|output: &mut O|{
state.interpret(output, &arg0)
});
let content = thunk(move|output: &mut O|state.interpret(output, &arg0));
align(alignment, content).draw(output)
},
@ -154,7 +178,7 @@ pub fn eval_view <'a, O: Screen + 'a, S> (
_ => return Ok(None)
}).transpose()
}
}
/// Interpret TUI-specific layout operation.
@ -180,7 +204,7 @@ pub fn eval_view <'a, O: Screen + 'a, S> (
pub fn eval_view_tui <'a, S> (
state: &S, output: &mut Tui, expr: impl Expression + 'a
) -> Perhaps<XYWH<u16>> where
S: Interpret<Tui, XYWH<u16>>
S: Interpret<Tui, Option<XYWH<u16>>>
+ for<'b>Namespace<'b, bool>
+ for<'b>Namespace<'b, u16>
+ for<'b>Namespace<'b, Color>
@ -208,7 +232,7 @@ pub fn eval_view_tui <'a, S> (
output.show(fg(color, thunk(move|output: &mut Tui|{
state.interpret(output, &arg1)?;
// FIXME?: don't max out the used area?
Ok(output.area().into())
Ok(Some(output.area().into()))
})))
},
@ -218,7 +242,7 @@ pub fn eval_view_tui <'a, S> (
output.show(bg(color, thunk(move|output: &mut Tui|{
state.interpret(output, &arg1)?;
// FIXME?: don't max out the used area?
Ok(output.area().into())
Ok(Some(output.area().into()))
})))
},