diff options
| author | Danilo M. <danix@danix.xyz> | 2026-09-17 19:15:59 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-09-17 19:15:59 +0200 |
| commit | 7b34edc8e7079a16755e342694173e9d194425d7 (patch) | |
| tree | 57025a7f382a4170f6d34e01c16772da016b2541 /lib | |
| parent | 8a6c0730f8e9f2c1e6033d3e66d2c524d7b9f91d (diff) | |
| download | conky-theme-udt-7b34edc8e7079a16755e342694173e9d194425d7.tar.gz conky-theme-udt-7b34edc8e7079a16755e342694173e9d194425d7.zip | |
feat: add the network card
Two lines on one chart against a shared ceiling, one sample per pixel column
so nothing is interpolated. The history is module state sized from the card's
width, so moving the card reframes the window rather than clearing it.
The public address is refused once stale: an address that may no longer be
yours, displayed with confidence, is worse than a dash.
The fixture uses TEST-NET-1. This repository is public.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/data.lua | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/data.lua b/lib/data.lua index 98c6898..4803f5b 100644 --- a/lib/data.lua +++ b/lib/data.lua @@ -378,4 +378,29 @@ function M.board_name(vendor, name) return name or vendor end +-- The IPv4 address from `ip -4 addr show <iface>` output. +-- +-- Split from the command that produces it so it can be tested against a +-- fixture: every other parser in this file follows the same split, and an +-- address is exactly the kind of value that must not be hardcoded in a test. +function M.iface_addr_parse(text) + if type(text) ~= 'string' then return nil end + return text:match('inet%s+(%d+%.%d+%.%d+%.%d+)') +end + +-- The interface's IPv4 address, or nil when it has none. +-- +-- This shells out, which the draw hook otherwise never does, so the caller +-- memoizes it: an address does not change without an event this dashboard +-- does not watch. Retried while nil, because a bridge may not be up when +-- conky starts. +function M.iface_addr(iface) + if type(iface) ~= 'string' then return nil end + local p = io.popen('ip -4 addr show ' .. ("%q"):format(iface) .. ' 2>/dev/null') + if not p then return nil end + local out = p:read('*a') + p:close() + return M.iface_addr_parse(out) +end + return M |
