Skip to content

Commit

Permalink
Predefined variables/Magic vars (#117)
Browse files Browse the repository at this point in the history
* basic idea

* generates docs

* hardcoded the gen script

* trying to hide magic vars

* eww-state is good now

* structure for cpu var is now there

* renamed cpu to diskstat, bc lib supports it after all

* not going to implement disk IO. go back to this commit, to see a rough idea

* removed it

* formatting

* stopped data race

* Update src/config/system_stats/ram.rs

Co-authored-by: ElKowar <[email protected]>

* Update src/config/system_stats/disk.rs

Co-authored-by: ElKowar <[email protected]>

* Explains macos better

* Update battery.rs

* Function for each OS when getting battery, a bit cleaner

* reworked battery a little

* all in one big file

* facepalm

* cleaner gen script and one huge file for the system stat stuff

* merge conflicts

* github interface for resolving merge conflicts sucks, this fixes it

* Apply suggestions from code review

Co-authored-by: ElKowar <[email protected]>

* Update src/config/inbuilt.rs

Co-authored-by: ElKowar <[email protected]>

* Apply suggestions from code review

Co-authored-by: ElKowar <[email protected]>

* code suggestions

* component temperature is a json struct

* newlines in magic vars descriptions

* disks is now json, numbers are not wrapped in strings, and more idiomatic code

* Update gen-docs.ts

Co-authored-by: mlvzk <[email protected]>

* removes a unneeded heading

* more doc updates and EWW_CPU_USAGE is now json

* calculates battery total avg and it's a json struct

Co-authored-by: ElKowar <[email protected]>
Co-authored-by: mlvzk <[email protected]>
  • Loading branch information
3 people authored May 11, 2021
1 parent 6eea3e0 commit df5793b
Show file tree
Hide file tree
Showing 15 changed files with 433 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: denoland/setup-deno@main
with:
deno-version: "v1.x"
- run: deno run --allow-read gen-docs.ts ./src/widgets/widget_definitions.rs >> ./docs/content/main/widgets.md
- run: deno run --allow-read --allow-write gen-docs.ts ./src/widgets/widget_definitions.rs ./src/config/inbuilt.rs

# Build & deploy
- name: shalzz/zola-deploy-action
Expand Down
131 changes: 109 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ futures-core = "0.3"
futures-util = "0.3"
tokio-util = "0.6"

sysinfo = "0.16.1"

nom = "6.1"
dyn-clone = "1.0"
Expand Down
13 changes: 13 additions & 0 deletions docs/content/main/magic-vars.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
+++
title = "Magic Variables"
slug = "magic variables documenation"
weight = 3
+++

These are variables that are always there, without you having to import them.

The delay between the updating variables is always 2s.


## Updating magic variables

1 change: 1 addition & 0 deletions docs/content/main/widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ title = "Widgets"
slug = "widget documentation"
weight = 3
+++

22 changes: 20 additions & 2 deletions gen-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ interface Widget {
isVisible: boolean;
}

function parseMagicVariables(data: string) {
const pattern = /^.*\/\/\s*@desc\s*(\w+)\s*-\s*(.*)$/gm;
let output = [];
for (const [_, name, desc] of data.matchAll(pattern)) {
output.push(
`### \`${name}\`
${desc.replaceAll("\\n", "\n\n")}
`);
}
return output.join("\n");
}

function parseVars(code: string): Record<string, string> {
const VAR_PATTERN = /^.*\/\/+ *@var +(.*?) +- +(.*)$/;
const vars: Record<string, string> = {};
Expand Down Expand Up @@ -121,7 +133,7 @@ function printDocs(vars: Record<string, string>, docs: Record<string, Widget>) {
.map((x) => printWidget(x))
.map((x) => x.replace(/\$\w+/g, (x) => vars[x.replace("$", "")]))
.join("\n\n");
console.log(output);
return output;
}

function printWidget(widget: Widget) {
Expand All @@ -138,7 +150,13 @@ ${widget.props.map((prop) => `- **\`${prop.name}\`**: *\`${prop.type}\`* ${prop.
// deno run --allow-read gen-docs.ts ./src/widgets/widget_definitions.ts 2> /dev/null
Deno.readTextFile(Deno.args[0]).then(data => {
const vars = parseVars(data);
printDocs(vars, parseDocs(data));
Deno.writeTextFile("docs/content/main/widgets.md", printDocs(vars, parseDocs(data)), {"append": true});
}).catch(err => {
return console.error(err);
})

let magic = Deno.readTextFile(Deno.args[1]).then(data => {
Deno.writeTextFile("docs/content/main/magic-vars.md", parseMagicVariables(data), {"append": true});
}).catch(err => {
return console.error(err);
})
Loading

0 comments on commit df5793b

Please sign in to comment.