From 68e6d7b00dd463989b43a6564a4024d224f6cb4d Mon Sep 17 00:00:00 2001 From: legendofmiracles <30902201+legendofmiracles@users.noreply.github.com> Date: Mon, 8 Nov 2021 10:51:00 -0600 Subject: [PATCH] add properties to magic vars (#343) --- crates/eww/src/config/inbuilt.rs | 6 ++++++ gen-docs.ts | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/crates/eww/src/config/inbuilt.rs b/crates/eww/src/config/inbuilt.rs index 74b4bcb..26a1a46 100644 --- a/crates/eww/src/config/inbuilt.rs +++ b/crates/eww/src/config/inbuilt.rs @@ -26,15 +26,19 @@ macro_rules! builtin_vars { pub fn get_inbuilt_vars() -> HashMap { builtin_vars! {Duration::new(2, 0), // @desc EWW_TEMPS - Heat of the components in Celcius + // @prop { : temperature } "EWW_TEMPS" => || 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())), // @desc EWW_DISK - Information on on all mounted partitions (Might report inaccurately on some filesystems, like btrfs)\nExample: `{EWW_DISK["/"]}` + // @prop { : { name, total, free, used, used_perc } } "EWW_DISK" => || Ok(DynVal::from(get_disks())), // @desc EWW_BATTERY - Battery capacity in procent of the main battery + // @prop { : { capacity, status } } "EWW_BATTERY" => || Ok(DynVal::from( match get_battery_capacity() { Err(e) => { @@ -46,9 +50,11 @@ pub fn get_inbuilt_vars() -> HashMap { )), // @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())), // @desc EWW_NET - Bytes up/down on all interfaces + // @prop { : { up, down } } "EWW_NET" => || Ok(DynVal::from(net())), } } diff --git a/gen-docs.ts b/gen-docs.ts index e0b1955..6ef7b53 100644 --- a/gen-docs.ts +++ b/gen-docs.ts @@ -14,12 +14,20 @@ interface Widget { function parseMagicVariables(data: string) { const pattern = /^.*\/\/\s*@desc\s*(\w+)\s*-\s*(.*)$/gm; + const prop_pattern = /^.*\/\/\s+@prop +\s*(.*)$/gm; + let properties = [...data.matchAll(prop_pattern)] let output = []; + let i = 0; for (const [_, name, desc] of data.matchAll(pattern)) { output.push( `### \`${name}\` ${desc.replaceAll("\\n", "\n\n")} +#### Structure +\`\`\` +${properties[i][1]} +\`\`\` `); + i = i + 1 } return output.join("\n"); }