From 859b173a1ea3e645df0cb91d6d008bc002f38aef Mon Sep 17 00:00:00 2001 From: facile pop culture reference Date: Thu, 30 Jul 2026 18:05:32 +0300 Subject: [PATCH] test: add get_color (bulky!) --- src/eval.rs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/eval.rs b/src/eval.rs index 5359216..e0df0f1 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -192,8 +192,9 @@ pub fn eval_view <'a, O: Screen + 'a, S> ( /// #[namespace(bool)] /// #[namespace(u8)] /// #[namespace(u16)] -/// #[namespace(Color try_to_color)] +/// #[namespace(Color get_color)] /// struct State; +/// /// impl Interpret>> for State { /// fn interpret_expr <'a> (&'a self, _: &mut Tui, lang: &'a impl Expression) /// -> Usually>> @@ -202,6 +203,36 @@ pub fn eval_view <'a, O: Screen + 'a, S> ( /// } /// } /// +/// fn get_color (state: &State, src: impl Language) -> Perhaps { +/// 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"))?; +/// Ok(Some(Color::Rgb(n, n, n))) +/// }, +/// (Some("rgb"), Some(tail)) => { +/// let r: u8 = state.namespace(tail.head().map_err(Into::into))? +/// .ok_or(LanguageError::Domain("not red"))?; +/// let g: u8 = state.namespace(tail.tail().head().map_err(Into::into))? +/// .ok_or(LanguageError::Domain("not green"))?; +/// let b: u8 = state.namespace(tail.tail().tail().head().map_err(Into::into))? +/// .ok_or(LanguageError::Domain("not blue"))?; +/// Ok(Some(Color::Rgb(r, g, b))) +/// }, +/// (Some(_), _) => return Err(format!("not a color expression: {expr}").into()), +/// (None, _) => return Err(format!("not a color expression: {expr}").into()), +/// } +/// } else if let Ok(Some(sym)) = src.word() { +/// Ok(match sym { +/// ":color/bg" => Some(Color::Rgb(28, 32, 36)), +/// ":color/fg" => Some(Color::Rgb(98, 92, 96)), +/// _ => return Err(format!("not a color: {sym}").into()) +/// }) +/// } else { +/// return Err(format!("not a color: {:?}", src.src()?).into()) +/// } +/// } +/// /// # fn main () -> tengri::Usually<()> { /// let state = State; /// let mut out = Tui::new(80, 25);