@@ -35,25 +35,10 @@ const ELIDED_TAIL = 4;
3535 /// One announced call, held until its result commits the line to scrollback.
3636 const PendingCall = struct { name: []const u8, summary: []const u8 };
3737
38-/// Rows the queue block may occupy, including its overflow row.
39-const MAX_QUEUE_ROWS = 5;
40-
4138 /// Width every state word is padded to, so the tool heads align.
4239 const STATE_WIDTH = "running".len;
4340 const STATE_PAD = std.fmt.comptimePrint("{{s: <{d}}}", .{STATE_WIDTH});
4441
45-/// Clips one call to a single row: head and tail of `text` with a dim mark
46-/// between them. A bad argument can sit at either end, so the tail is kept.
47-fn clipCall(a: std.mem.Allocator, text: []const u8, available: usize) []const u8 {
48- if (available == 0) return "";
49- // One wrapped element means the text fits.
50- if (render.wrapLine(a, text, available).len == 1) return text;
51- const head_budget = available / 2;
52- const head = render.wrapLine(a, text, head_budget)[0];
53- const tails = render.wrapLine(a, text, available - 1 - head_budget);
54- return std.fmt.allocPrint(a, "{s}{s}{s}", .{ head, styles.dim(a, "…"), tails[tails.len - 1] }) catch text;
55-}
56-
5742 fn paintRow(a: std.mem.Allocator, line: []const u8) []const u8 {
5843 return std.fmt.allocPrint(a, "{s}{s}\x1b[K", .{ theme.SGR_PLAIN, line }) catch line;
5944 }
@@ -109,6 +94,16 @@ fn callHead(a: std.mem.Allocator, name: []const u8) []const u8 {
10994 return styles.teal(a, std.fmt.allocPrint(a, "-> {s}", .{name}) catch "->");
11095 }
11196
97+/// The rows of one announced call: the state word and the tool head, then the
98+/// arguments, wrapped at `width`.
99+fn callRows(a: std.mem.Allocator, width: usize, call: PendingCall, running: bool) []const []const u8 {
100+ const padded = std.fmt.allocPrint(a, STATE_PAD, .{if (running) "running" else "queued"}) catch "";
101+ const word = if (running) styles.teal(a, padded) else styles.dim(a, padded);
102+ const head = callHead(a, call.name);
103+ const text = render.expandTabs(a, render.sanitize(a, call.summary), 4);
104+ return render.wrapLine(a, std.fmt.allocPrint(a, "{s} {s} {s}", .{ word, head, text }) catch text, width);
105+}
106+
112107 fn collapseWs(a: std.mem.Allocator, s: []const u8) []const u8 {
113108 var out: std.ArrayList(u8) = .empty;
114109 var i: usize = 0;
@@ -526,26 +521,23 @@ const Tui = struct {
526521 return " ";
527522 }
528523
529- /// Styled rows for the queue block, one row per call, clipped to `width`.
530- fn queueRows(self: *Tui, width: usize) []const []const u8 {
524+ /// Styled rows for the announced calls, wrapped to `width` and capped at
525+ /// `budget` rows. The running call is drawn first, so its arguments are what
526+ /// survives a full region; the tail the cap cuts is counted in one dim row.
527+ /// The block never exceeds its budget, which keeps the live region's row
528+ /// count exact.
529+ fn queueRows(self: *Tui, width: usize, budget: usize) []const []const u8 {
530+ if (budget == 0) return &.{};
531531 var out: std.ArrayList([]const u8) = .empty;
532- const calls = self.pending_calls.items;
533- const overflow = calls.len > MAX_QUEUE_ROWS;
534- const shown = if (overflow) MAX_QUEUE_ROWS - 1 else calls.len;
535- for (calls[0..shown], 0..) |call, i| {
536- const running = i == 0 and self.phase == .running_tool;
537- const label = if (running) "running" else "queued";
538- const padded = std.fmt.allocPrint(self.s, STATE_PAD, .{label}) catch label;
539- const word = if (running) styles.teal(self.s, padded) else styles.dim(self.s, padded);
540- const head = callHead(self.s, call.name);
541- const prefix = STATE_WIDTH + 1 + "-> ".len + call.name.len + 1;
542- const available = if (width > prefix) width - prefix else 0;
543- const text = render.expandTabs(self.s, render.sanitize(self.s, call.summary), 4);
544- out.append(self.s, std.fmt.allocPrint(self.s, "{s} {s} {s}", .{ word, head, clipCall(self.s, text, available) }) catch "") catch {};
545- }
546- if (overflow) {
547- out.append(self.s, styles.dim(self.s, std.fmt.allocPrint(self.s, "... {d} more queued ...", .{calls.len - shown}) catch "...")) catch {};
532+ for (self.pending_calls.items, 0..) |call, i| {
533+ for (callRows(self.s, width, call, i == 0 and self.phase == .running_tool)) |row| out.append(self.s, row) catch {};
548534 }
535+ if (out.items.len <= budget) return out.items;
536+ // The last budgeted row carries the count of the rows that do not fit.
537+ const keep = budget - 1;
538+ const hidden = out.items.len - keep;
539+ out.shrinkRetainingCapacity(keep);
540+ out.append(self.s, styles.dim(self.s, std.fmt.allocPrint(self.s, "... {d} more lines ...", .{hidden}) catch "...")) catch {};
549541 return out.items;
550542 }
551543
@@ -562,8 +554,9 @@ const Tui = struct {
562554 const rows = renderRows(self.s, inflight, width);
563555
564556 const room = if (height > status.len + 1) height - status.len - 1 else 0;
565- const queue_all = self.queueRows(width);
566- const queue = queue_all[0..@min(queue_all.len, room)];
557+ // Announced calls wrap, so their row count is not known until they are
558+ // built; the cap keeps the block inside the room the body shares.
559+ const queue = self.queueRows(width, room);
567560 const keep = @min(rows.len, room - queue.len);
568561 const body = rows[rows.len - keep ..];
569562 const ed = self.editor.render2(width, @max(height - status.len - queue.len - body.len, 1));