test: add get_color (bulky!)

This commit is contained in:
facile pop culture reference 2026-07-30 18:05:32 +03:00
parent 8d2445d728
commit 859b173a1e

View file

@ -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<Tui, Option<XYWH<u16>>> for State {
/// fn interpret_expr <'a> (&'a self, _: &mut Tui, lang: &'a impl Expression)
/// -> Usually<Option<XYWH<u16>>>
@ -202,6 +203,36 @@ pub fn eval_view <'a, O: Screen + 'a, S> (
/// }
/// }
///
/// fn get_color (state: &State, src: impl Language) -> Perhaps<Color> {
/// 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);