diff --git a/examples/mode_02.rs b/examples/mode_02.rs index a077f20..1ec2069 100644 --- a/examples/mode_02.rs +++ b/examples/mode_02.rs @@ -42,9 +42,7 @@ impl_keywords!(Tui, XYWH, State [ kw_push, kw_tui_text, kw_tui_fg, - kw_tui_bg, - kw_color_g, - kw_color_rgb, + kw_tui_bg ]); impl Interpret>> for State { diff --git a/src/layout/azimuth.rs b/src/layout/azimuth.rs index 2eeb0af..ac749b8 100644 --- a/src/layout/azimuth.rs +++ b/src/layout/azimuth.rs @@ -38,6 +38,7 @@ fn_kw_layout!(kw_align |state, output, expr| { draw(move|output: &mut O|{state.interpret(output, &expr.tail().head())}).align( eval_enum!("align", output, state, expr.head().src()?.unwrap_or_default().split("/").skip(1).next(), + expr.tail().head(), Azimuth { "c" => C, "x" => X, "y" => Y, "n" => N, "s" => S, "e" => E, "w" => W, @@ -130,7 +131,7 @@ fn_kw_layout!(kw_split |state, output, expr| { let head = expr.head(); let mut frags = head.src()?.unwrap_or_default().split("/"); Ok(matches!(frags.next(), Some("bsp")).then(||{ - eval_enum!("bsp", output, state, frags.next(), Split { + eval_enum!("bsp", output, state, frags.next(), expr.tail().head()?, Split { "n" => North, "s" => South, "e" => East, @@ -139,10 +140,10 @@ fn_kw_layout!(kw_split |state, output, expr| { "b" => Below }).stack( draw(move|output: &mut O|{ - state.interpret(output, &expr.tail().head()?) + state.interpret(output, &expr.tail().tail().head()?) }), draw(move|output: &mut O|{ - state.interpret(output, &expr.tail().tail().head()?) + state.interpret(output, &expr.tail().tail().tail().head()?) }), ).draw(output) }).transpose()?.flatten()) diff --git a/src/layout/iter.rs b/src/layout/iter.rs index bd80aae..e1cb3d9 100644 --- a/src/layout/iter.rs +++ b/src/layout/iter.rs @@ -43,23 +43,10 @@ pub fn iter_east_fixed <'a, S: Screen, D: 'a, I: Iterator, U: Draw> draw(move|_to: &mut S|{ todo!() }) } -pub fn iter_south <'a, S: Screen, D: Draw, I: Iterator> ( - iter: impl Fn()->I +pub fn iter_south <'a, S: Screen, D: 'a, I: Iterator, U: Draw> ( + _iter: impl Fn()->I, _draw: impl Fn(D, usize)->U, ) -> impl Draw { - draw(move|to: &mut S|{ - let XYWH(x, mut y, w, mut h) = to.area(); - let h0 = h; - for item in iter() { - if let Some(used) = to.draw(Some(XYWH(x, y, w, h)), item)? { - y = y.add(used.y()); - h = h.minus(used.y()); - if h == S::Unit::zero() { - break; - } - } - } - Ok(Some(XYWH(x, y, w, h))) - }) + draw(move|_to: &mut S|{ todo!() }) } pub fn iter_south_fixed <'a, S: Screen, D: 'a, I: Iterator, U: Draw> ( diff --git a/src/lib.rs b/src/lib.rs index fd39be3..119bd52 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -182,7 +182,7 @@ pub trait AsMutOpt { fn as_mut_opt (&mut self) -> Option<&mut T>; } /// Some layout operations exist in multiple variants that take a single argument. /// Their handling in [eval_view] is uniform and goes like this: macro_rules! eval_enum (( - $name:literal, $output:ident, $state:ident, $value:expr, $Enum:ident { + $name:literal, $output:ident, $state:ident, $value:expr, $arg0:expr, $Enum:ident { $($v:literal => $V:ident),* $(,)? } ) => {{ @@ -252,11 +252,10 @@ macro_rules! eval_xy ( #[cfg(feature = "exit")] pub use self::exit::*; #[cfg(feature = "exit")] mod exit { use crate::*; - use std::sync::{Arc, atomic::{AtomicBool, Ordering::Relaxed}}; + use std::sync::{Arc, atomic::AtomicBool}; use crossterm::event::*; - #[derive(Clone, Default, Debug)] - pub struct Exit(Arc); + #[derive(Clone)] pub struct Exit(Arc); impl Exit { pub fn run (run: impl FnOnce(Self)->Usually) -> Usually { @@ -270,9 +269,6 @@ macro_rules! eval_xy ( state: KeyEventState::NONE })) } - pub fn exit (&self) { - self.0.store(true, Relaxed) - } } impl AsRef> for Exit { diff --git a/src/term.rs b/src/term.rs index 298dacb..9a66b5d 100644 --- a/src/term.rs +++ b/src/term.rs @@ -145,14 +145,16 @@ impl Tui { panic(info); })); } - pub fn run_main (exit: Exit, state: Arc>) -> Usually<()> where + pub fn run_main (state: Arc>) -> Usually<()> where T: View + Apply> + Send + Sync + 'static { - let scan = Duration::from_millis(100); - let frame = Duration::from_millis(10); - let (_input, output) = Tui::io(exit.as_ref(), &state, scan, frame, std::io::stdout())?; - let _ = output.join(); - Tui::teardown(&mut stdout()) + Exit::run(|exit|{ + let scan = Duration::from_millis(100); + let frame = Duration::from_millis(10); + let (_input, output) = Tui::io(exit.as_ref(), &state, scan, frame, std::io::stdout())?; + let _ = output.join(); + Tui::teardown(&mut stdout()) + }) } /// Spawn the TUI input and output threadsl. pub fn io < @@ -498,7 +500,7 @@ impl> Draw for ShowSizeOf { } } -#[cfg(feature = "eval")] fn_kw_layout_tui!(kw_tui_text |_state, output, expr| { +#[cfg(feature = "eval")] fn_kw_layout_tui!(kw_tui_text |state, output, expr| { Ok(matches!(expr.head()?, Some("text")).then(||{ if let Some(src) = expr.tail().src()? { src.draw(output) diff --git a/src/term/modify.rs b/src/term/modify.rs index 5a7512c..176971a 100644 --- a/src/term/modify.rs +++ b/src/term/modify.rs @@ -36,8 +36,7 @@ impl Tui { if let Some(expr) = src.expr()? { match (expr.head()?, expr.tail()?) { (Some("g"), Some(tail)) => { - let n: u8 = state.namespace(tail.head().map_err(Into::into))? - .ok_or(LanguageError::Domain("not gray"))?; + let n: u8 = state.namespace(tail.head().map_err(Into::into))?.ok_or(LanguageError::Domain("not gray"))?; Ok(Some(Color::Rgb(n, n, n))) }, (Some("rgb"), Some(tail)) => {