diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/card.lua | 1 | ||||
| -rw-r--r-- | lib/data.lua | 39 |
2 files changed, 40 insertions, 0 deletions
diff --git a/lib/card.lua b/lib/card.lua index 2313141..dde4121 100644 --- a/lib/card.lua +++ b/lib/card.lua @@ -133,6 +133,7 @@ M.ICON = { breaktimer = '\u{F13AB}', -- timer calendar = '\u{F0E17}', -- calendar-month immich = '\u{F02F9}', -- image-multiple + updates = '\u{F03D5}', -- package-up } -- The gap between a title's icon and its text. One constant so the measured diff --git a/lib/data.lua b/lib/data.lua index c66aa42..4b31f43 100644 --- a/lib/data.lua +++ b/lib/data.lua @@ -631,4 +631,43 @@ function M.immich_parse(text) return out end +-- nvtable's plain table (`nvtable -C -E`), as bin/updates-sample.sh caches it: +-- +-- [personal] foo-bin 1.14.9 -> 1.14.9 !! ~ 1.14.10 +-- <repo> <name> <installed> -> <shipped> <marker> [~] [upstream] +-- +-- followed by a summary line with the counts. The marker is '!!' (installed +-- behind upstream), 'ok' or '-' (not installed); '~' flags the shipped .info +-- as behind. Upstream appears only when shipped does not already show it. +-- +-- Returns the rows as { repo, name, installed, shipped, upstream, behind, +-- bump } with '--' turned into nil, plus .upgrade/.bump/.current/.missing +-- counts, or nil when the text has neither rows nor a summary. +function M.nvtable_parse(text) + if type(text) ~= 'string' then return nil end + local out, seen = {}, false + local function v(s) return s ~= '--' and s or nil end + for line in text:gmatch('[^\n]+') do + local repo, name, inst, ship, rest = + line:match('^%s*%[(.-)%]%s+(%S+)%s+(%S+)%s+%->%s+(%S+)%s*(.*)$') + if repo then + local mark, tail = rest:match('^(%S*)%s*(.*)$') + local bump = tail:match('^~') ~= nil + if bump then tail = tail:gsub('^~%s*', '') end + out[#out + 1] = { + repo = v(repo), name = name, installed = v(inst), shipped = v(ship), + upstream = tail:match('^(%S+)'), behind = mark == '!!', bump = bump, + } + seen = true + elseif line:match('to upgrade') then + out.upgrade = tonumber(line:match('(%d+) to upgrade')) + out.bump = tonumber(line:match('(%d+) repos? to bump')) + out.current = tonumber(line:match('(%d+) current')) + out.missing = tonumber(line:match('(%d+) not installed')) or 0 + seen = true + end + end + return seen and out or nil +end + return M |
