mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-07-17 15:56:57 +02:00
and exits, weirdly. wonder what's up here
This commit is contained in:
parent
b0fb9f013d
commit
b44dc02f33
9 changed files with 110 additions and 80 deletions
36
src/eval.rs
36
src/eval.rs
|
|
@ -16,7 +16,7 @@ use dizzle::*;
|
|||
/// struct State {/*app-specific*/}
|
||||
/// impl<'b> Namespace<'b, bool> for State {}
|
||||
/// impl<'b> Namespace<'b, u16> for State {}
|
||||
/// impl Understand<Target, ()> for State {}
|
||||
/// impl Interpret<Target, ()> for State {}
|
||||
///
|
||||
/// # fn main () -> tengri::Usually<()> {
|
||||
/// let state = State {};
|
||||
|
|
@ -30,7 +30,7 @@ use dizzle::*;
|
|||
#[cfg(feature = "dsl")] pub fn eval_view <'a, O: Screen + 'a, S> (
|
||||
state: &S, output: &mut O, expr: &'a impl Expression
|
||||
) -> Usually<bool> where
|
||||
S: Understand<O, ()>
|
||||
S: Interpret<O, ()>
|
||||
+ for<'b>Namespace<'b, bool>
|
||||
+ for<'b>Namespace<'b, O::Unit>
|
||||
{
|
||||
|
|
@ -52,18 +52,18 @@ use dizzle::*;
|
|||
|
||||
Some("when") => output.place(&when(
|
||||
state.namespace(arg0?)?.unwrap(),
|
||||
move|output: &mut O|state.understand(output, &arg1)
|
||||
move|output: &mut O|state.interpret(output, &arg1)
|
||||
)),
|
||||
|
||||
Some("either") => output.place(&either(
|
||||
state.namespace(arg0?)?.unwrap(),
|
||||
move|output: &mut O|state.understand(output, &arg1),
|
||||
move|output: &mut O|state.understand(output, &arg2),
|
||||
move|output: &mut O|state.interpret(output, &arg1),
|
||||
move|output: &mut O|state.interpret(output, &arg2),
|
||||
)),
|
||||
|
||||
Some("bsp") => output.place(&{
|
||||
let a = move|output: &mut O|state.understand(output, &arg0);
|
||||
let b = move|output: &mut O|state.understand(output, &arg1);
|
||||
let a = move|output: &mut O|state.interpret(output, &arg0);
|
||||
let b = move|output: &mut O|state.interpret(output, &arg1);
|
||||
bsp(match frags.next() {
|
||||
Some("n") => Alignment::N,
|
||||
Some("s") => Alignment::S,
|
||||
|
|
@ -76,7 +76,7 @@ use dizzle::*;
|
|||
}),
|
||||
|
||||
Some("align") => output.place(&{
|
||||
let a = move|output: &mut O|state.understand(output, &arg0).unwrap();
|
||||
let a = move|output: &mut O|state.interpret(output, &arg0).unwrap();
|
||||
align(match frags.next() {
|
||||
Some("c") => Alignment::Center,
|
||||
Some("n") => Alignment::N,
|
||||
|
|
@ -90,7 +90,7 @@ use dizzle::*;
|
|||
}),
|
||||
|
||||
Some("fill") => output.place(&{
|
||||
let a = move|output: &mut O|state.understand(output, &arg0).unwrap();
|
||||
let a = move|output: &mut O|state.interpret(output, &arg0).unwrap();
|
||||
match frags.next() {
|
||||
Some("xy") | None => fill_wh(a),
|
||||
Some("x") => fill_w(a),
|
||||
|
|
@ -102,7 +102,7 @@ use dizzle::*;
|
|||
Some("exact") => output.place(&{
|
||||
let axis = frags.next();
|
||||
let arg = match axis { Some("x") | Some("y") => arg1, Some("xy") | None => arg2, _ => panic!("exact: unsupported axis {axis:?}") };
|
||||
let cb = move|output: &mut O|state.understand(output, &arg).unwrap();
|
||||
let cb = move|output: &mut O|state.interpret(output, &arg).unwrap();
|
||||
match axis {
|
||||
Some("xy") | None => exact_wh(state.namespace(arg0?)?.unwrap(), state.namespace(arg1?)?.unwrap(), cb),
|
||||
Some("x") => exact_w(state.namespace(arg0?)?.unwrap(), cb),
|
||||
|
|
@ -115,7 +115,7 @@ use dizzle::*;
|
|||
Some("min") => output.place(&{
|
||||
let axis = frags.next();
|
||||
let arg = match axis { Some("x") | Some("y") => arg1, Some("xy") | None => arg2, _ => panic!("min: unsupported axis {axis:?}") };
|
||||
let cb = move|output: &mut O|state.understand(output, &arg).unwrap();
|
||||
let cb = move|output: &mut O|state.interpret(output, &arg).unwrap();
|
||||
match axis {
|
||||
Some("xy") | None => min_wh(state.namespace(arg0?)?.unwrap(), state.namespace(arg1?)?.unwrap(), cb),
|
||||
Some("x") => min_w(state.namespace(arg0?)?.unwrap(), cb),
|
||||
|
|
@ -127,7 +127,7 @@ use dizzle::*;
|
|||
Some("max") => output.place(&{
|
||||
let axis = frags.next();
|
||||
let arg = match axis { Some("x") | Some("y") => arg1, Some("xy") | None => arg2, _ => panic!("max: unsupported axis {axis:?}") };
|
||||
let cb = move|output: &mut O|state.understand(output, &arg).unwrap();
|
||||
let cb = move|output: &mut O|state.interpret(output, &arg).unwrap();
|
||||
match axis {
|
||||
Some("xy") | None => max_wh(state.namespace(arg0?)?.unwrap(), state.namespace(arg1?)?.unwrap(), cb),
|
||||
Some("x") => max_w(state.namespace(arg0?)?.unwrap(), cb),
|
||||
|
|
@ -139,7 +139,7 @@ use dizzle::*;
|
|||
Some("push") => output.place(&{
|
||||
let axis = frags.next();
|
||||
let arg = match axis { Some("x") | Some("y") => arg1, Some("xy") | None => arg2, _ => panic!("push: unsupported axis {axis:?}") };
|
||||
let cb = move|output: &mut O|state.understand(output, &arg);
|
||||
let cb = move|output: &mut O|state.interpret(output, &arg);
|
||||
match axis {
|
||||
Some("xy") | None => push_xy(state.namespace(arg0?)?.unwrap(), state.namespace(arg1?)?.unwrap(), cb),
|
||||
Some("x") => push_x(state.namespace(arg0?)?.unwrap(), cb),
|
||||
|
|
@ -157,13 +157,13 @@ use dizzle::*;
|
|||
/// Interpret TUI-specific layout operation.
|
||||
///
|
||||
/// ```
|
||||
/// use tengri::{Namespace, Understand, Tui, ratatui::prelude::Color};
|
||||
/// use tengri::{Namespace, Interpret, Tui, ratatui::prelude::Color};
|
||||
///
|
||||
/// struct State;
|
||||
/// impl<'b> Namespace<'b, bool> for State {}
|
||||
/// impl<'b> Namespace<'b, u16> for State {}
|
||||
/// impl<'b> Namespace<'b, Color> for State {}
|
||||
/// impl Understand<Tui, ()> for State {}
|
||||
/// impl Interpret<Tui, ()> for State {}
|
||||
/// # fn main () -> tengri::Usually<()> {
|
||||
/// let state = State;
|
||||
/// let mut out = Tui::default();
|
||||
|
|
@ -177,7 +177,7 @@ use dizzle::*;
|
|||
pub fn eval_view_tui <'a, S> (
|
||||
state: &S, output: &mut Tui, expr: impl Expression + 'a
|
||||
) -> Usually<bool> where
|
||||
S: Understand<Tui, ()>
|
||||
S: Interpret<Tui, ()>
|
||||
+ for<'b>Namespace<'b, bool>
|
||||
+ for<'b>Namespace<'b, u16>
|
||||
+ for<'b>Namespace<'b, Color>
|
||||
|
|
@ -201,7 +201,7 @@ pub fn eval_view_tui <'a, S> (
|
|||
let arg0 = arg0?.expect("fg: expected arg 0 (color)");
|
||||
let color = Namespace::namespace(state, arg0)?.unwrap_or_else(||panic!("fg: {arg0:?}: not a color"));
|
||||
output.place(&fg(color, thunk(move|output: &mut Tui|{
|
||||
state.understand(output, &arg1)?;
|
||||
state.interpret(output, &arg1)?;
|
||||
// FIXME?: don't max out the used area?
|
||||
Ok(output.area().into())
|
||||
})))
|
||||
|
|
@ -211,7 +211,7 @@ pub fn eval_view_tui <'a, S> (
|
|||
let arg0 = arg0?.expect("bg: expected arg 0 (color)");
|
||||
let color = Namespace::namespace(state, arg0)?.unwrap_or_else(||panic!("bg: {arg0:?}: not a color"));
|
||||
output.place(&bg(color, thunk(move|output: &mut Tui|{
|
||||
state.understand(output, &arg1)?;
|
||||
state.interpret(output, &arg1)?;
|
||||
// FIXME?: don't max out the used area?
|
||||
Ok(output.area().into())
|
||||
})))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue