mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-08-07 14:16:56 +02:00
test: add get_color (bulky!)
This commit is contained in:
parent
8d2445d728
commit
859b173a1e
1 changed files with 32 additions and 1 deletions
33
src/eval.rs
33
src/eval.rs
|
|
@ -192,8 +192,9 @@ pub fn eval_view <'a, O: Screen + 'a, S> (
|
||||||
/// #[namespace(bool)]
|
/// #[namespace(bool)]
|
||||||
/// #[namespace(u8)]
|
/// #[namespace(u8)]
|
||||||
/// #[namespace(u16)]
|
/// #[namespace(u16)]
|
||||||
/// #[namespace(Color try_to_color)]
|
/// #[namespace(Color get_color)]
|
||||||
/// struct State;
|
/// struct State;
|
||||||
|
///
|
||||||
/// impl Interpret<Tui, Option<XYWH<u16>>> for State {
|
/// impl Interpret<Tui, Option<XYWH<u16>>> for State {
|
||||||
/// fn interpret_expr <'a> (&'a self, _: &mut Tui, lang: &'a impl Expression)
|
/// fn interpret_expr <'a> (&'a self, _: &mut Tui, lang: &'a impl Expression)
|
||||||
/// -> Usually<Option<XYWH<u16>>>
|
/// -> 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<()> {
|
/// # fn main () -> tengri::Usually<()> {
|
||||||
/// let state = State;
|
/// let state = State;
|
||||||
/// let mut out = Tui::new(80, 25);
|
/// let mut out = Tui::new(80, 25);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue