diff options
| author | t <t@tjp.lol> | 2026-08-26 09:16:23 -0600 |
|---|---|---|
| committer | t <t@tjp.lol> | 2026-08-26 09:17:36 -0600 |
| commit | ed872974d799312c7114a63474c6bc7bc2179e2c (patch) | |
| tree | c1af127d89f04e617eb8109a71805e91bfdc4521 | |
| parent | eeb3499f58fa909df7074e689c0f029c59ea767f (diff) | |
Use Panto terminal width helpers for progress rendering
| -rw-r--r-- | spec/fake_ext.lua | 22 | ||||
| -rw-r--r-- | spec/test_progress.lua | 2 | ||||
| -rw-r--r-- | subagents/progress.lua | 28 |
3 files changed, 27 insertions, 25 deletions
diff --git a/spec/fake_ext.lua b/spec/fake_ext.lua index 88c4b56..fce012b 100644 --- a/spec/fake_ext.lua +++ b/spec/fake_ext.lua @@ -50,6 +50,27 @@ local M = {} +-- Enough of panto.text for progress-renderer specs; dedicated host tests cover +-- the real terminal-width implementation. +M.text = { + truncate = function(value, width) + return tostring(value or ""):sub(1, math.max(0, width)) + end, + wrap = function(value, width) + width = math.max(1, width) + value = tostring(value or "") + if value == "" then return { "" } end + local rows = {} + for line in (value .. "\n"):gmatch("(.-)\n") do + repeat + rows[#rows + 1] = line:sub(1, width) + line = line:sub(width + 1) + until line == "" + end + return rows + end, +} + -- --------------------------------------------------------------------------- -- luv stand-in, installed once when this module loads -- --------------------------------------------------------------------------- @@ -806,6 +827,7 @@ function M.install(opts) handle.ext = ext package.loaded.panto = { ext = ext, + text = M.text, agent = new_agent, file_system_jsonl_store = function(arg) return new_store("fs", arg) diff --git a/spec/test_progress.lua b/spec/test_progress.lua index 76cd289..c8bf684 100644 --- a/spec/test_progress.lua +++ b/spec/test_progress.lua @@ -1,3 +1,5 @@ +local fake = require("spec.fake_ext") +package.loaded.panto = { text = fake.text } local progress = require("subagents.progress") local function board(id, collapsed) diff --git a/subagents/progress.lua b/subagents/progress.lua index b39fe00..aee198b 100644 --- a/subagents/progress.lua +++ b/subagents/progress.lua @@ -51,31 +51,9 @@ local function display_tool_name(name) return type(name) == "string" and name:gsub("__", ".") or "tool" end -local function prefix(text, width) - if width < 1 then return "" end - local count, stop = 0, 0 - local ok = pcall(function() - for pos in utf8.codes(text) do - if count == width then break end - stop = pos - count = count + 1 - end - if count > 0 then stop = (utf8.offset(text, count + 1) or (#text + 1)) - 1 end - end) - if not ok then return text:sub(1, width) end - return text:sub(1, stop) -end - local function wrap(text, width, emit) - width = math.max(1, width) - text = sanitize(text) - if text == "" then emit(""); return end - local rest = text - while rest ~= "" do - local piece = prefix(rest, width) - if piece == "" then piece = rest:sub(1, 1) end - emit(piece) - rest = rest:sub(#piece + 1) + for _, row in ipairs(require("panto").text.wrap(sanitize(text), math.max(1, width))) do + emit(row) end end @@ -267,7 +245,7 @@ local function render(board, width) for _, card in ipairs(board.cards) do local sid = card.sid ~= "" and (" " .. card.sid:sub(1, sid_width) .. (sid_width < #card.sid and "…" or "")) or "" - out[#out + 1] = prefix(sanitize(string.format("%s %s%s — %s", + out[#out + 1] = require("panto").text.truncate(sanitize(string.format("%s %s%s — %s", GLYPHS[card.status] or GLYPHS.running, card.label, sid, card.status)), width) local lines = body_lines(card, width - #BODY_INDENT, board.collapsed) for _, line in ipairs(lines) do out[#out + 1] = line end |
