diff --git a/crates/eww/src/config/inbuilt.rs b/crates/eww/src/config/inbuilt.rs index bca0f22..13cf1e6 100644 --- a/crates/eww/src/config/inbuilt.rs +++ b/crates/eww/src/config/inbuilt.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, time::Duration}; +use std::collections::HashMap; use simplexpr::{dynval::DynVal, SimplExpr}; use yuck::config::{ @@ -10,7 +10,7 @@ use crate::{config::system_stats::*, paths::EwwPaths}; use eww_shared_util::VarName; macro_rules! define_builtin_vars { - ($($name:literal => $fun:expr => $interval:expr),*$(,)?) => { + ($($name:literal [$interval:literal] => $fun:expr),*$(,)?) => { pub static INBUILT_VAR_NAMES: &[&'static str] = &[$($name),*]; pub fn get_inbuilt_vars() -> HashMap { maplit::hashmap! { @@ -20,7 +20,7 @@ macro_rules! define_builtin_vars { run_while_expr: SimplExpr::Literal(DynVal::from(true)), command: VarSource::Function($fun), initial_value: None, - interval: $interval, + interval: std::time::Duration::from_secs($interval), name_span: eww_shared_util::span::Span::DUMMY, }) ),* @@ -32,19 +32,19 @@ macro_rules! define_builtin_vars { define_builtin_vars! { // @desc EWW_TEMPS - Heat of the components in Celcius // @prop { : temperature } - "EWW_TEMPS" => || Ok(DynVal::from(get_temperatures())) => Duration::new(2, 0), + "EWW_TEMPS" [2] => || Ok(DynVal::from(get_temperatures())), // @desc EWW_RAM - Information on ram and swap usage in kB. // @prop { total_mem, free_mem, total_swap, free_swap, available_mem, used_mem, used_mem_perc } - "EWW_RAM" => || Ok(DynVal::from(get_ram())) => Duration::new(2, 0), + "EWW_RAM" [2] => || Ok(DynVal::from(get_ram())), // @desc EWW_DISK - Information on on all mounted partitions (Might report inaccurately on some filesystems, like btrfs and zfs) Example: `{EWW_DISK["/"]}` // @prop { : { name, total, free, used, used_perc } } - "EWW_DISK" => || Ok(DynVal::from(get_disks())) => Duration::new(2, 0), + "EWW_DISK" [2] => || Ok(DynVal::from(get_disks())), // @desc EWW_BATTERY - Battery capacity in procent of the main battery // @prop { : { capacity, status } } - "EWW_BATTERY" => || Ok(DynVal::from( + "EWW_BATTERY" [2] => || Ok(DynVal::from( match get_battery_capacity() { Err(e) => { log::error!("Couldn't get the battery capacity: {:?}", e); @@ -52,18 +52,18 @@ define_builtin_vars! { } Ok(o) => o, } - )) => Duration::new(2, 0), + )), // @desc EWW_CPU - Information on the CPU cores: frequency and usage (No MacOS support) // @prop { cores: [{ core, freq, usage }], avg } - "EWW_CPU" => || Ok(DynVal::from(get_cpus())) => Duration::new(2, 0), + "EWW_CPU" [2] => || Ok(DynVal::from(get_cpus())) , // @desc EWW_NET - Bytes up/down on all interfaces // @prop { : { up, down } } - "EWW_NET" => || Ok(DynVal::from(net())) => Duration::new(2, 0), + "EWW_NET" [2] => || Ok(DynVal::from(net())) , - // @desc EWW_TIME - Information on current time in UNIX timestamp - "EWW_TIME" => || Ok(DynVal::from(get_time())) => Duration::new(1, 0), + // @desc EWW_TIME - the current UNIX timestamp + "EWW_TIME" [1] => || Ok(DynVal::from(get_time())) , } macro_rules! define_magic_constants { diff --git a/crates/eww/src/config/system_stats.rs b/crates/eww/src/config/system_stats.rs index 37e56cf..46f201b 100644 --- a/crates/eww/src/config/system_stats.rs +++ b/crates/eww/src/config/system_stats.rs @@ -179,5 +179,5 @@ pub fn net() -> String { } pub fn get_time() -> String { - format!("{}", chrono::offset::Utc::now().format("%s")) + chrono::offset::Utc::now().timestamp().to_string() } diff --git a/crates/simplexpr/src/eval.rs b/crates/simplexpr/src/eval.rs index 490119d..c0b029d 100644 --- a/crates/simplexpr/src/eval.rs +++ b/crates/simplexpr/src/eval.rs @@ -57,11 +57,11 @@ pub enum EvalError { #[error(transparent)] JaqParseError(JaqParseError), - #[error("{1}")] - Spanned(Span, Box), - #[error("Error parsing date: {0}")] ChronoError(String), + + #[error("{1}")] + Spanned(Span, Box), } static_assertions::assert_impl_all!(EvalError: Send, Sync); @@ -382,7 +382,7 @@ fn call_expr_function(name: &str, args: Vec) -> Result Err(EvalError::WrongArgCount(name.to_string())), }, "formattime" => match args.as_slice() { - [timestamp, timezone, format] => { + [timestamp, format, timezone] => { let timezone = match chrono_tz::Tz::from_str(&timezone.as_string()?) { Ok(x) => x, Err(_) => return Err(EvalError::ChronoError("Invalid timezone".to_string())), diff --git a/docs/src/expression_language.md b/docs/src/expression_language.md index d804563..57e15ea 100644 --- a/docs/src/expression_language.md +++ b/docs/src/expression_language.md @@ -47,7 +47,7 @@ Supported currently are the following features: - `arraylength(value)`: Gets the length of the array - `objectlength(value)`: Gets the amount of entries in the object - `jq(value, jq_filter_string)`: run a [jq](https://stedolan.github.io/jq/manual/) style command on a json value. (Uses [jaq](https://crates.io/crates/jaq) internally). - - `formattime(unix_timestamp, timezone, format_str)`: Gets the time in a given format from UNIX timestamp. + - `formattime(unix_timestamp, format_str, timezone)`: Gets the time in a given format from UNIX timestamp. Check [chrono's documentation](https://docs.rs/chrono/latest/chrono/format/strftime/index.html) for more information about format string and [chrono-tz's documentation](https://docs.rs/chrono-tz/latest/chrono_tz/enum.Tz.html) for available time zones.