smizzle
Some checks are pending
/ build (push) Waiting to run

This commit is contained in:
facile pop culture reference 2026-08-19 18:21:34 +03:00
parent a9f2fa2cdd
commit 291ab63224
11 changed files with 98 additions and 96 deletions

View file

@ -3,15 +3,14 @@ use crate::*;
fn_kw_layout!(kw_when |state, output, expr| {
let thunk = draw(move|screen|ok_flat(expr.nth(2)?.map(|x: &'a str|state.interpret(screen, x))));
ok_flat(matches!(expr.head()?, Some("when")).then(||{
when(state.namespace(expr.nth(1)?)?.unwrap(), thunk) .draw(output)
when(state.namespace(&expr.nth(1)?)?.unwrap(), thunk) .draw(output)
}))
});
/// Only render when condition is true.
///
/// ```
/// # use tengri::*;
/// # fn test () -> impl Draw<Tui> {
/// # use ::tengri::*; fn test <'a> () -> impl Draw<'a, Tui> {
/// when(true, "Yes")
/// # }
/// ```
@ -23,15 +22,14 @@ fn_kw_layout!(kw_either |state, output, expr| {
let thunk_a = draw(move|screen|ok_flat(expr.nth(2)?.map(|x: &'a str|state.interpret(screen, x))));
let thunk_b = draw(move|screen|ok_flat(expr.nth(3)?.map(|x: &'a str|state.interpret(screen, x))));
ok_flat(matches!(expr.head()?, Some("either")).then(||{
either(state.namespace(expr.nth(1)?)?.unwrap(), thunk_a, thunk_b).draw(output)
either(state.namespace(&expr.nth(1)?)?.unwrap(), thunk_a, thunk_b).draw(output)
}))
});
/// Render one thing if a condition is true and another false.
///
/// ```
/// # use tengri::*;
/// # fn test () -> impl Draw<Tui> {
/// # use ::tengri::*; fn test <'a> () -> impl Draw<'a, Tui> {
/// either(true, "Yes", "No")
/// # }
/// ```