summaryrefslogtreecommitdiffstats
path: root/.config/fastfetch
diff options
context:
space:
mode:
authorPavel Egorov <[email protected]>2025-12-16 14:20:51 +0300
committerPavel Egorov <[email protected]>2025-12-16 14:20:51 +0300
commit4150244bc05b0adc380c8c1af7a31fea9d7b8a53 (patch)
treede480a8ccd4e8f6f339aaf3823400a01f9d0729f /.config/fastfetch
parent12856fb677df10b11032e5e84b871a50ee14e16a (diff)
downloaddotfiles-4150244bc05b0adc380c8c1af7a31fea9d7b8a53.tar.gz
dotfiles-4150244bc05b0adc380c8c1af7a31fea9d7b8a53.zip
[fastfetch] code cleanup
Diffstat (limited to '.config/fastfetch')
-rw-r--r--.config/fastfetch/confgen.py54
1 files changed, 30 insertions, 24 deletions
diff --git a/.config/fastfetch/confgen.py b/.config/fastfetch/confgen.py
index 22c53bc..e8b1383 100644
--- a/.config/fastfetch/confgen.py
+++ b/.config/fastfetch/confgen.py
@@ -67,14 +67,14 @@ class Node:
67 67
68 return module | key | format | text | additional_entries 68 return module | key | format | text | additional_entries
69 69
70 def collect_branch(self): 70 def collect_branch(self) -> list[dict]:
71 return [self.construct_module()] + [node.collect_branch() for node in self.children] 71 return [self.construct_module()] + [node.collect_branch() for node in self.children]
72 72
73 def add_children(self, *nodes: type["Node"]) -> type["Node"]: 73 def add_children(self, *nodes: type["Node"]) -> type["Node"]:
74 self.children += nodes 74 self.children += nodes
75 return self 75 return self
76 76
77 def remove_module(self, module): 77 def remove_module(self, module) -> None:
78 for i, node in enumerate(self.children): 78 for i, node in enumerate(self.children):
79 if node.module == module: 79 if node.module == module:
80 del self.children[i] 80 del self.children[i]
@@ -82,12 +82,6 @@ class Node:
82 node.remove_module(module) 82 node.remove_module(module)
83 83
84 84
85schema = {
86 "$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json"
87}
88
89logo = {"padding": {"left": 3, "right": 3, "top": 3}}
90
91font_effects = { 85font_effects = {
92 "reset": "#0", 86 "reset": "#0",
93 "software": "\u001b[38;2;0;255;0m", 87 "software": "\u001b[38;2;0;255;0m",
@@ -204,25 +198,37 @@ roots = [
204 ) 198 )
205] 199]
206 200
207modules = {"modules": list(flatten(root.collect_branch() for root in roots))}
208 201
209with NamedTemporaryFile(mode='w', delete_on_close=False, suffix=".jsonc") as tmp_config: 202def build_config(roots) -> dict[str, type[Any]]:
210 json.dump(schema | logo | modules, tmp_config) 203 schema = {
211 tmp_config.flush() 204 "$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json"
205 }
212 206
213 fastfetch_response = subprocess.run( 207 logo = {"padding": {"left": 3, "right": 3, "top": 3}}
214 ["fastfetch", "--config", tmp_config.name, "--json"], 208
215 capture_output=True 209 modules = {"modules": list(flatten(root.collect_branch() for root in roots))}
216 ) 210
211 return schema | logo | modules
212
213
214def get_test_response() -> list[dict]:
215 with NamedTemporaryFile(mode='w', delete_on_close=False, suffix=".jsonc") as tmp_config:
216 json.dump(build_config(roots), tmp_config)
217 tmp_config.flush()
218
219 fastfetch_response = subprocess.run(
220 ["fastfetch", "--config", tmp_config.name, "--json"],
221 capture_output=True
222 )
217 223
218fastfetch_data = json.loads(fastfetch_response.stdout) 224 return json.loads(fastfetch_response.stdout)
219 225
220skip_modules = ["Custom"]
221for response_object in fastfetch_data:
222 if response_object.get("error") and response_object.get("type") not in skip_modules or response_object.get("result") == []:
223 for root in roots:
224 root.remove_module(response_object.get("type").lower())
225 226
226modules = {"modules": list(flatten(root.collect_branch() for root in roots))} 227def filter_roots(roots) -> list[Node]:
228 skip_modules = ["Custom"]
229 for response_object in get_test_response():
230 if response_object.get("error") and response_object.get("type") not in skip_modules or response_object.get("result") == []:
231 for root in roots:
232 root.remove_module(response_object.get("type").lower())
233 return roots
227 234
228print(json.dumps(modules))