diff --git a/src/draw/screen.rs b/src/draw/screen.rs index eab296b..857031d 100644 --- a/src/draw/screen.rs +++ b/src/draw/screen.rs @@ -22,5 +22,6 @@ use super::*; pub trait Screen: Space + Send + Sync + Sized { type Unit: Coord; /// Render drawable in subarea specified by `area` - fn show <'t, T: Draw> (&mut self, area: XYWH, content: T); + fn show <'t, T: Draw> (&mut self, area: XYWH, content: T) -> + Usually>; } diff --git a/src/eval.rs b/src/eval.rs index 8709747..b64b83e 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -77,7 +77,7 @@ macro_rules! eval_enum (( /// ``` pub fn eval_view <'a, O: Screen + 'a, S> ( state: &S, output: &mut O, expr: &'a impl Expression -) -> Usually where +) -> Perhaps> where S: Interpret> + for<'b> Namespace<'b, bool> + for<'b> Namespace<'b, O::Unit> @@ -100,7 +100,7 @@ pub fn eval_view <'a, O: Screen + 'a, S> ( let arg2 = tail1.head(); // First `frags.next()` calls returns the namespace. - match frags.next() { + Some(match frags.next() { Some("when") => when( state.namespace(arg0?)?.unwrap(), @@ -132,26 +132,30 @@ pub fn eval_view <'a, O: Screen + 'a, S> ( ).draw(output), Some("exact") => eval_xy!( - "exact", expr, head, output, state, frags.next(), arg0, arg1, arg2, wh_exact, w_exact, h_exact - ), - Some("min") => eval_xy!( - "min", expr, head, output, state, frags.next(), arg0, arg1, arg2, wh_min, w_min, h_min - ), - Some("max") => eval_xy!( - "max", expr, head, output, state, frags.next(), arg0, arg1, arg2, wh_max, w_max, h_max - ), - Some("push") => eval_xy!( - "push", expr, head, output, state, frags.next(), arg0, arg1, arg2, xy_push, x_push, y_push + "exact", expr, head, output, state, frags.next(), + arg0, arg1, arg2, wh_exact, w_exact, h_exact ), - _ => return Ok(false) + Some("min") => eval_xy!( + "min", expr, head, output, state, frags.next(), + arg0, arg1, arg2, wh_min, w_min, h_min + ), - }?; + Some("max") => eval_xy!( + "max", expr, head, output, state, frags.next(), + arg0, arg1, arg2, wh_max, w_max, h_max + ), - Ok(true) + Some("push") => eval_xy!( + "push", expr, head, output, state, frags.next(), + arg0, arg1, arg2, xy_push, x_push, y_push + ), + + _ => return Ok(None) + + }).transpose() } - /// Interpret TUI-specific layout operation. /// /// ``` @@ -174,8 +178,8 @@ 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 -) -> Usually where - S: Interpret +) -> Perhaps> where + S: Interpret> + for<'b>Namespace<'b, bool> + for<'b>Namespace<'b, u16> + for<'b>Namespace<'b, Color> @@ -187,11 +191,13 @@ pub fn eval_view_tui <'a, S> ( let arg0 = args.head(); let tail0 = args.tail(); let arg1 = tail0.head(); - match frags.next() { + Ok(Some(match frags.next() { Some("text") => { if let Some(src) = args?.src()? { - output.show(output.xywh(), &src) + output.show(output.xywh(), &src)? + } else { + return Ok(None) } }, @@ -202,7 +208,7 @@ pub fn eval_view_tui <'a, S> ( state.interpret(output, &arg1)?; // FIXME?: don't max out the used area? Ok(output.area().into()) - }))) + })))? }, Some("bg") => { @@ -212,11 +218,10 @@ pub fn eval_view_tui <'a, S> ( state.interpret(output, &arg1)?; // FIXME?: don't max out the used area? Ok(output.area().into()) - }))) + })))? }, - _ => return Ok(false) + _ => return Ok(None) - }; - Ok(true) + })) } diff --git a/src/term.rs b/src/term.rs index b5fa807..57caf15 100644 --- a/src/term.rs +++ b/src/term.rs @@ -194,11 +194,12 @@ impl Screen for Tui { /// Render drawable in subarea specified by `area` fn show <'t, T: Draw> ( &mut self, area: XYWH, content: T - ) { + ) -> Usually> { let previous_area = self.1; self.1 = area; - let _result_area = content.draw(self); + let result_area = content.draw(self); self.1 = previous_area; + result_area } }