From 5b85512ccd0d87cb61c30f73cea262c7a0545d37 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Tue, 10 Nov 2026 18:23:20 +0100 Subject: feat(stats): an OS row with logo, kernel and uptime The System card's small 'up Nh' line becomes a full-width tile: the distro's Nerd Font logo, NAME and VERSION_ID from /etc/os-release in large type, the codename and kernel release below, and the uptime large on the right. An unknown distro gets Tux. Co-Authored-By: Claude Opus 5.5 --- deckit/modules/stats.py | 12 ++++++++++++ static/deck.css | 4 ++++ static/modules/stats.js | 21 +++++++++++++++++---- tests/test_stats.py | 6 ++++++ 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/deckit/modules/stats.py b/deckit/modules/stats.py index a764246..a60605e 100644 --- a/deckit/modules/stats.py +++ b/deckit/modules/stats.py @@ -20,6 +20,7 @@ The Arc driver exposes temperature and fan through hwmon and no VRAM capacity; VRAM in use comes from the DRM fdinfo scan, as quickshell's perf panel does. """ +import platform import re import shlex import socket @@ -100,6 +101,15 @@ def _cpu_name(cpuinfo): return None +def _os(text): + """/etc/os-release -> {"id", "name", "codename"}.""" + f = {k: v.strip().strip('"') for k, _, v in + (line.partition("=") for line in text.splitlines()) if v} + name = " ".join(filter(None, (f.get("NAME"), f.get("VERSION_ID")))) + return {"id": f.get("ID", "linux"), "name": name or "Linux", + "codename": f.get("VERSION_CODENAME", "")} + + def _gpu_name(lspci): """lspci -mm's line -> 'Intel Arc B580': the vendor's first word, then the marketing name in brackets, else the whole device name.""" @@ -144,6 +154,7 @@ def make(cfg: dict) -> Module: battery = _battery(hw) gpu = _gpu(hw) cpu_name = _cpu_name(_read("/proc/cpuinfo")) or "CPU" + os_info = {**_os(_read("/etc/os-release")), "kernel": platform.release()} gpu_total = _parse_bytes(hw.get("gpu_mem_total", "")) if gpu else None prev = {"cpu": None, "net": None, "t": None, "gpu_t": 0, "gpu_v": None} @@ -196,6 +207,7 @@ def make(cfg: dict) -> Module: t = _read(cpu_sensor) if cpu_sensor else "" return { "host": socket.gethostname(), + "os": os_info, "uptime": int(float(_read("/proc/uptime", "0").split()[0])), "cpu": cpu_percent(), "cpuName": cpu_name, diff --git a/static/deck.css b/static/deck.css index 4e9b753..b16ac7f 100644 --- a/static/deck.css +++ b/static/deck.css @@ -286,6 +286,10 @@ select { .msub { font-size: 0.857rem; color: var(--udt-subtext0); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .tablet .bars { height: 0.8em; margin-left: 6px; vertical-align: baseline; fill: var(--udt-surface2); } .tablet .bars .lit { fill: var(--udt-accent); } +.msys { grid-column: 1 / -1; flex-direction: row; align-items: center; gap: 14px; } +.msys > i { flex: none; width: 3rem; font-size: 2.6rem; line-height: 1; color: var(--udt-accent); } +.msys > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; } +.msys .mup { margin-left: auto; align-items: flex-end; flex: none; } .mfoot { margin-top: 10px; font-size: 0.857rem; color: var(--udt-overlay0); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .windows { display: flex; flex-direction: column; gap: 14px; } diff --git a/static/modules/stats.js b/static/modules/stats.js index e280e47..0e35a91 100644 --- a/static/modules/stats.js +++ b/static/modules/stats.js @@ -23,6 +23,12 @@ const uptime = (s) => { return d ? `${d}d ${h}h` : `${h}h`; }; +// Nerd Font distro logos; anything else gets Tux. +const DISTRO = { + slackware: "\uf318", arch: "\uf303", debian: "\uf306", fedora: "\uf30a", + ubuntu: "\uf31b", gentoo: "\uf30d", opensuse: "\uf314", void: "\uf32e", +}; + function tile(label, value, sub) { const d = document.createElement("div"); d.className = "mtile"; @@ -58,9 +64,16 @@ export default { g ? `${bytes(g.memUsed)} / ${bytes(g.memTotal)} GiB` : "no GPU"), tile("Network", `↓${rate(st.net.down)} ↑${rate(st.net.up)}`), ); - const foot = document.createElement("div"); - foot.className = "mfoot"; - foot.textContent = `up ${uptime(st.uptime)}`; - box.append(foot); + const os = st.os ?? {}; + const sys = document.createElement("div"); + sys.className = "mtile msys"; + sys.innerHTML = `
+
uptime
`; + sys.querySelector("i").textContent = DISTRO[os.id] ?? "\uf17c"; + sys.querySelector("div .mvalue").textContent = os.name ?? "Linux"; + sys.querySelector(".msub").textContent = + [os.codename, `Linux ${os.kernel ?? ""}`].filter(Boolean).join(" · "); + sys.querySelector(".mup .mvalue").textContent = uptime(st.uptime); + box.append(sys); }, }; diff --git a/tests/test_stats.py b/tests/test_stats.py index f32bfac..f732054 100644 --- a/tests/test_stats.py +++ b/tests/test_stats.py @@ -45,6 +45,12 @@ class Names(unittest.TestCase): "Intel Core i7-8550U") self.assertIsNone(stats._cpu_name("")) + def test_os(self): + self.assertEqual(stats._os('NAME=Slackware\nVERSION_ID=16.0\nID=slackware\n' + 'VERSION_CODENAME=current\n'), + {"id": "slackware", "name": "Slackware 16.0", "codename": "current"}) + self.assertEqual(stats._os(""), {"id": "linux", "name": "Linux", "codename": ""}) + def test_gpu_name(self): line = ('03:00.0 "VGA compatible controller" "Intel Corporation" ' '"Battlemage G21 [Arc B580]" -p00 "Vendor" "Device 4215"') -- cgit v1.2.3