mirror of
https://github.com/elkowar/eww.git
synced 2024-08-17 07:40:58 +03:00
add properties to magic vars (#343)
This commit is contained in:
parent
2bdf8d4915
commit
68e6d7b00d
@ -26,15 +26,19 @@ macro_rules! builtin_vars {
|
||||
pub fn get_inbuilt_vars() -> HashMap<VarName, ScriptVarDefinition> {
|
||||
builtin_vars! {Duration::new(2, 0),
|
||||
// @desc EWW_TEMPS - Heat of the components in Celcius
|
||||
// @prop { <name>: 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 { <mount_point>: { 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 { <name>: { capacity, status } }
|
||||
"EWW_BATTERY" => || Ok(DynVal::from(
|
||||
match get_battery_capacity() {
|
||||
Err(e) => {
|
||||
@ -46,9 +50,11 @@ pub fn get_inbuilt_vars() -> HashMap<VarName, ScriptVarDefinition> {
|
||||
)),
|
||||
|
||||
// @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 { <name>: { up, down } }
|
||||
"EWW_NET" => || Ok(DynVal::from(net())),
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user