From f1be1bef9c3563fd78f811f54e5a64b1d993e4da Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Thu, 17 Sep 2026 19:06:06 +0200 Subject: feat: parse the sampler's key/value cache format Only the first space separates, so a value keeps its own spaces. Values stay strings: the sampler writes epochs and the widget decides whether an age reads as hours or days. Co-Authored-By: Claude Sonnet 5 --- lib/data.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib') diff --git a/lib/data.lua b/lib/data.lua index 9f20d1f..13e5ebd 100644 --- a/lib/data.lua +++ b/lib/data.lua @@ -279,4 +279,22 @@ function M.du_parse(text) return { total = total, items = items } end +-- Parse 'key value' lines into a table of strings. +-- +-- Values stay strings and are converted by the caller. The sampler writes +-- epochs as integers and the widget decides whether an age reads as hours or +-- days; a parser that guessed would have to know that. +-- +-- Only the first space separates, so a value keeps its own spaces: +-- 'version Slackware 15.0+' yields 'Slackware 15.0+', not 'Slackware'. +function M.kv_parse(text) + local out = {} + if type(text) ~= 'string' then return out end + for line in text:gmatch('[^\n]+') do + local k, v = line:match('^(%S+)%s+(.*)$') + if k and v ~= '' then out[k] = v end + end + return out +end + return M -- cgit v1.2.3