From a06ea2ac139d09ab9eba5931455c43a3a75f4151 Mon Sep 17 00:00:00 2001 From: same mf who else Date: Sat, 28 Mar 2026 14:44:11 +0200 Subject: [PATCH] enable and patch up mod eval --- src/eval.rs | 26 +++++++++++++++----------- src/lib.rs | 43 ++++++++++++++++++++++++++++++++++++++++++- src/play.rs | 42 ------------------------------------------ src/space.rs | 12 +++++++++--- src/term.rs | 2 +- 5 files changed, 67 insertions(+), 58 deletions(-) delete mode 100644 src/play.rs diff --git a/src/eval.rs b/src/eval.rs index d47aae6..0089ee3 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -1,4 +1,5 @@ -use crate::*; +use crate::{*, term::*, draw::*, ratatui::prelude::*}; +use dizzle::*; /// Interpret layout operation. /// @@ -165,7 +166,7 @@ use crate::*; /// impl Understand for State {} /// # fn main () -> tengri::Usually<()> { /// let state = State; -/// let mut out = TuiOut::default(); +/// let mut out = Tui::default(); /// tengri::eval_view_tui(&state, &mut out, "")?; /// tengri::eval_view_tui(&state, &mut out, "text Hello world!")?; /// tengri::eval_view_tui(&state, &mut out, "fg (g 0) (text Hello world!)")?; @@ -174,9 +175,9 @@ use crate::*; /// # Ok(()) } /// ``` pub fn eval_view_tui <'a, S> ( - state: &S, output: &mut Buffer, expr: impl Expression + 'a + state: &S, output: &mut Tui, expr: impl Expression + 'a ) -> Usually where - S: Understand + S: Understand + for<'b>Namespace<'b, bool> + for<'b>Namespace<'b, u16> + for<'b>Namespace<'b, Color> @@ -199,18 +200,21 @@ pub fn eval_view_tui <'a, S> ( Some("fg") => { let arg0 = arg0?.expect("fg: expected arg 0 (color)"); let color = Namespace::namespace(state, arg0)?.unwrap_or_else(||panic!("fg: {arg0:?}: not a color")); - let thunk = Thunk::new(move|output: &mut Buffer|state.understand(output, &arg1).unwrap()); - output.place(&TuiOut::fg(color, thunk)) + output.place(&fg(color, thunk(move|output: &mut Tui|{ + state.understand(output, &arg1)?; + // FIXME?: don't max out the used area? + Ok(output.area().into()) + }))) }, Some("bg") => { - //panic!("expr: {expr:?}\nhead: {head:?}\nfrags: {frags:?}\nargs: {args:?}\narg0: {arg0:?}\ntail0: {tail0:?}\narg1: {arg1:?}\ntail1: {tail1:?}\narg2: {arg2:?}"); - //panic!("head: {head:?}\narg0: {arg0:?}\narg1: {arg1:?}\narg2: {arg2:?}");; - //panic!("head: {head:?}\narg0: {arg0:?}\narg1: {arg1:?}\narg2: {arg2:?}"); let arg0 = arg0?.expect("bg: expected arg 0 (color)"); let color = Namespace::namespace(state, arg0)?.unwrap_or_else(||panic!("bg: {arg0:?}: not a color")); - let thunk = Thunk::new(move|output: &mut Buffer|state.understand(output, &arg1).unwrap()); - output.place(&TuiOut::bg(color, thunk)) + output.place(&bg(color, thunk(move|output: &mut Tui|{ + state.understand(output, &arg1)?; + // FIXME?: don't max out the used area? + Ok(output.area().into()) + }))) }, _ => return Ok(false) diff --git a/src/lib.rs b/src/lib.rs index 349ca17..a5668c3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,10 +25,10 @@ pub(crate) use ::{ #[cfg(feature = "lang")] pub extern crate dizzle as lang; #[cfg(feature = "lang")] pub use ::dizzle::{self, Usually, Perhaps, impl_default}; +#[cfg(feature = "lang")] pub mod eval; #[cfg(feature = "time")] pub mod time; -#[cfg(feature = "play")] pub mod play; #[cfg(feature = "play")] pub mod exit; #[cfg(feature = "play")] pub mod task; @@ -39,6 +39,7 @@ pub(crate) use ::{ #[cfg(feature = "draw")] pub mod draw; #[cfg(feature = "draw")] pub mod space; #[cfg(feature = "draw")] pub mod color; + #[cfg(feature = "text")] pub mod text; #[cfg(feature = "term")] pub mod term; #[cfg(feature = "term")] pub mod keys; @@ -75,3 +76,43 @@ pub(crate) use ::{ } }; ); + +/// Define an enum containing commands, and implement [Command] trait for over given `State`. +#[macro_export] macro_rules! def_command ( + ($Command:ident: |$state:ident: $State:ty| { + // FIXME: support attrs (docstrings) + $($Variant:ident$({$($arg:ident:$Arg:ty),+ $(,)?})?=>$body:expr),* $(,)? + })=>{ + #[derive(Debug)] pub enum $Command { + // FIXME: support attrs (docstrings) + $($Variant $({ $($arg: $Arg),* })?),* + } + impl ::tengri::dizzle::Act<$State> for $Command { + fn act (&self, $state: &mut $State) -> Perhaps { + match self { + $(Self::$Variant $({ $($arg),* })? => $body,)* + _ => unimplemented!("Act<{}>: {self:?}", stringify!($State)), + } + } + } + }); + +/// Implement [Handle] for given `State` and `handler`. +#[macro_export] macro_rules! impl_handle { + //(|$self:ident:$State:ty,$input:ident|$handler:expr) => { + //impl ::tengri::Handle for $State { + //fn handle (&mut $self, $input: &E) -> Perhaps { + //$handler + //} + //} + //}; + ($E:ty: |$self:ident:$State:ty,$input:ident|$handler:expr) => { + //impl ::tengri::Handle<$E> for $State { + //fn handle (&mut $self, $input: &$E) -> + //Perhaps<<$E as ::tengri::Input>::Handled> + //{ + //$handler + //} + //} + } +} diff --git a/src/play.rs b/src/play.rs deleted file mode 100644 index 96c83c4..0000000 --- a/src/play.rs +++ /dev/null @@ -1,42 +0,0 @@ -use crate::{*, time::*, lang::*}; -use ::std::{thread::JoinHandle, time::Duration}; - -/// Define an enum containing commands, and implement [Command] trait for over given `State`. -#[macro_export] macro_rules! def_command ( - ($Command:ident: |$state:ident: $State:ty| { - // FIXME: support attrs (docstrings) - $($Variant:ident$({$($arg:ident:$Arg:ty),+ $(,)?})?=>$body:expr),* $(,)? - })=>{ - #[derive(Debug)] pub enum $Command { - // FIXME: support attrs (docstrings) - $($Variant $({ $($arg: $Arg),* })?),* - } - impl ::tengri::dizzle::Act<$State> for $Command { - fn act (&self, $state: &mut $State) -> Perhaps { - match self { - $(Self::$Variant $({ $($arg),* })? => $body,)* - _ => unimplemented!("Act<{}>: {self:?}", stringify!($State)), - } - } - } - }); - -/// Implement [Handle] for given `State` and `handler`. -#[macro_export] macro_rules! impl_handle { - (|$self:ident:$State:ty,$input:ident|$handler:expr) => { - impl ::tengri::Handle for $State { - fn handle (&mut $self, $input: &E) -> Perhaps { - $handler - } - } - }; - ($E:ty: |$self:ident:$State:ty,$input:ident|$handler:expr) => { - impl ::tengri::Handle<$E> for $State { - fn handle (&mut $self, $input: &$E) -> - Perhaps<<$E as ::tengri::Input>::Handled> - { - $handler - } - } - } -} diff --git a/src/space.rs b/src/space.rs index 9039d42..b942f74 100644 --- a/src/space.rs +++ b/src/space.rs @@ -77,6 +77,15 @@ impl> Draw for Anchor { } } +pub const fn origin_c (a: impl Draw) -> impl Draw { + Anchor(Origin::C, a) +} +pub const fn origin_x (a: impl Draw) -> impl Draw { + Anchor(Origin::X, a) +} +pub const fn origin_y (a: impl Draw) -> impl Draw { + Anchor(Origin::Y, a) +} pub const fn origin_nw (a: impl Draw) -> impl Draw { Anchor(Origin::NW, a) } @@ -89,9 +98,6 @@ pub const fn origin_ne (a: impl Draw) -> impl Draw { pub const fn origin_w (a: impl Draw) -> impl Draw { Anchor(Origin::W, a) } -pub const fn origin_c (a: impl Draw) -> impl Draw { - Anchor(Origin::C, a) -} pub const fn origin_e (a: impl Draw) -> impl Draw { Anchor(Origin::E, a) } diff --git a/src/term.rs b/src/term.rs index c038785..32081c4 100644 --- a/src/term.rs +++ b/src/term.rs @@ -1,4 +1,4 @@ -use crate::{*, lang::*, play::*, draw::*, space::{*, Split::*}, color::*, text::*, task::*}; +use crate::{*, lang::*, draw::*, space::{*, Split::*}, color::*, text::*, task::*}; use unicode_width::{UnicodeWidthStr, UnicodeWidthChar}; use rand::distributions::uniform::UniformSampler; use ::{