From 4d55e9ad63d1fae887726dffcd25a32def23d34f Mon Sep 17 00:00:00 2001 From: ovalkonia <60359793+ovalkonia@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:57:48 +0300 Subject: [PATCH] Add `min` and `max` simplexpr functions (#1123) * Add 'min' and 'max' function calls to simplexpr * Add changelog entry for 'min' and 'max' simplexpr functions --- CHANGELOG.md | 1 + crates/simplexpr/src/eval.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32e2aa8..3530092 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to eww will be listed here, starting at changes since versio ### Features - Add `:truncate` property to labels, disabled by default (except in cases where truncation would be enabled in version `0.5.0` and before) (By: Rayzeq). - Add support for `:hover` css selectors for tray items (By: zeapoz) +- Add `min` and `max` function calls to simplexpr (By: ovalkonia) ## [0.6.0] (21.04.2024) diff --git a/crates/simplexpr/src/eval.rs b/crates/simplexpr/src/eval.rs index cad180d..f426b79 100644 --- a/crates/simplexpr/src/eval.rs +++ b/crates/simplexpr/src/eval.rs @@ -328,6 +328,22 @@ fn call_expr_function(name: &str, args: Vec) -> Result Err(EvalError::WrongArgCount(name.to_string())), }, + "min" => match args.as_slice() { + [a, b] => { + let a = a.as_f64()?; + let b = b.as_f64()?; + Ok(DynVal::from(f64::min(a, b))) + } + _ => Err(EvalError::WrongArgCount(name.to_string())), + }, + "max" => match args.as_slice() { + [a, b] => { + let a = a.as_f64()?; + let b = b.as_f64()?; + Ok(DynVal::from(f64::max(a, b))) + } + _ => Err(EvalError::WrongArgCount(name.to_string())), + }, "sin" => match args.as_slice() { [num] => { let num = num.as_f64()?;