From 7b34edc8e7079a16755e342694173e9d194425d7 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Thu, 17 Sep 2026 19:15:59 +0200 Subject: 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 --- lib/data.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lib') 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 ` 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 -- cgit v1.2.3