diff options
| author | Danilo M. <danix@danix.xyz> | 2026-09-17 19:06:06 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-09-17 19:06:06 +0200 |
| commit | f1be1bef9c3563fd78f811f54e5a64b1d993e4da (patch) | |
| tree | 7fc440ac31c01f1daba0645c4c13fbeb6cda24e6 /lib | |
| parent | 8e6f60fc8f442351bdc948d2142914d3946ce34d (diff) | |
| download | conky-theme-udt-f1be1bef9c3563fd78f811f54e5a64b1d993e4da.tar.gz conky-theme-udt-f1be1bef9c3563fd78f811f54e5a64b1d993e4da.zip | |
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 <noreply@anthropic.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/data.lua | 18 |
1 files changed, 18 insertions, 0 deletions
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 |
