xonecas.io
79113
Ma

mini-coding-agent / commit c88a430

feat: display pending bash calls.

xonecas2026-10-04 c88a4305397c73106e6def6897d67da10e9572c6 parent d8d7891

1 file changed

src/tui/tui.zig+60−8
@@ -32,6 +32,29 @@ const MAX_BODY_ROWS = 12;
3232 const ELIDED_HEAD = 4;
3333 const ELIDED_TAIL = 4;
3434
35+/// One announced call, held until its result commits the line to scrollback.
36+const PendingCall = struct { name: []const u8, summary: []const u8 };
37+
38+/// Rows the queue block may occupy, including its overflow row.
39+const MAX_QUEUE_ROWS = 5;
40+
41+/// Width every state word is padded to, so the tool heads align.
42+const STATE_WIDTH = "running".len;
43+const STATE_PAD = std.fmt.comptimePrint("{{s: <{d}}}", .{STATE_WIDTH});
44+
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. Testing through the wrapper
50+ // keeps SGR sequences out of the width, which `displayWidth` would count.
51+ if (render.wrapLine(a, text, available).len == 1) return text;
52+ const head_budget = available / 2;
53+ const head = render.wrapLine(a, text, head_budget)[0];
54+ const tails = render.wrapLine(a, text, available - 1 - head_budget);
55+ return std.fmt.allocPrint(a, "{s}{s}{s}", .{ head, styles.dim(a, "…"), tails[tails.len - 1] }) catch text;
56+}
57+
3558 fn paintRow(a: std.mem.Allocator, line: []const u8) []const u8 {
3659 return std.fmt.allocPrint(a, "{s}{s}\x1b[K", .{ theme.SGR_PLAIN, line }) catch line;
3760 }
@@ -367,7 +390,7 @@ const Tui = struct {
367390
368391 reply: stream.MarkdownStream,
369392 activity: stream.TailStream,
370- pending_calls: std.ArrayList(stream.BodyLine) = .empty,
393+ pending_calls: std.ArrayList(PendingCall) = .empty,
371394 streamed: std.ArrayList(u8) = .empty,
372395 turn_start: i64 = 0,
373396 frame: usize = 0,
@@ -504,6 +527,29 @@ const Tui = struct {
504527 return " ";
505528 }
506529
530+ /// Styled rows for the queue block, one row per call, clipped to `width`.
531+ fn queueRows(self: *Tui, width: usize) []const []const u8 {
532+ var out: std.ArrayList([]const u8) = .empty;
533+ const calls = self.pending_calls.items;
534+ const overflow = calls.len > MAX_QUEUE_ROWS;
535+ const shown = if (overflow) MAX_QUEUE_ROWS - 1 else calls.len;
536+ for (calls[0..shown], 0..) |call, i| {
537+ const running = i == 0 and self.phase == .running_tool;
538+ const label = if (running) "running" else "queued";
539+ const padded = std.fmt.allocPrint(self.s, STATE_PAD, .{label}) catch label;
540+ const word = if (running) styles.teal(self.s, padded) else styles.dim(self.s, padded);
541+ const head = callHead(self.s, call.name);
542+ const prefix = STATE_WIDTH + 1 + "-> ".len + call.name.len + 1;
543+ const available = if (width > prefix) width - prefix else 0;
544+ const text = render.expandTabs(self.s, render.sanitize(self.s, call.summary), 4);
545+ out.append(self.s, std.fmt.allocPrint(self.s, "{s} {s} {s}", .{ word, head, clipCall(self.s, text, available) }) catch "") catch {};
546+ }
547+ if (overflow) {
548+ out.append(self.s, styles.dim(self.s, std.fmt.allocPrint(self.s, "... {d} more queued ...", .{calls.len - shown}) catch "...")) catch {};
549+ }
550+ return out.items;
551+ }
552+
507553 // ---- drawing ---------------------------------------------------------
508554 fn draw(self: *Tui) void {
509555 if (self.closed) return;
@@ -516,15 +562,19 @@ const Tui = struct {
516562 if (inflight.len == 0) inflight = self.activity.pending();
517563 const rows = renderRows(self.s, inflight, width);
518564
519- const keep = @min(rows.len, if (height > status.len + 1) height - status.len - 1 else 0);
565+ const room = if (height > status.len + 1) height - status.len - 1 else 0;
566+ const queue_all = self.queueRows(width);
567+ const queue = queue_all[0..@min(queue_all.len, room)];
568+ const keep = @min(rows.len, room - queue.len);
520569 const body = rows[rows.len - keep ..];
521- const ed = self.editor.render2(width, @max(height - status.len - body.len, 1));
570+ const ed = self.editor.render2(width, @max(height - status.len - queue.len - body.len, 1));
522571
523572 var lines: std.ArrayList([]const u8) = .empty;
524573 for (body) |r| lines.append(self.s, paintRow(self.s, r)) catch {};
574+ for (queue) |r| lines.append(self.s, paintRow(self.s, r)) catch {};
525575 for (status) |r| lines.append(self.s, paintRow(self.s, r)) catch {};
526576 for (ed.rows) |r| lines.append(self.s, paintRow(self.s, r)) catch {};
527- var cursor_row = status.len + body.len + ed.cursor_row;
577+ var cursor_row = body.len + queue.len + status.len + ed.cursor_row;
528578 if (cursor_row >= lines.items.len and lines.items.len > 0) cursor_row = lines.items.len - 1;
529579
530580 const scroll = self.scroll.items;
@@ -572,8 +622,10 @@ const Tui = struct {
572622 self.keepName(&self.writing_tool, null);
573623 self.commitLines(self.reply.flush());
574624 self.activity.reset();
575- const summary = callSummary(self.a, tc.name, tc.arguments);
576- self.pending_calls.append(self.a, .{ .text = std.fmt.allocPrint(self.a, "{s} {s}", .{ callHead(self.a, tc.name), summary }) catch "" }) catch {};
625+ self.pending_calls.append(self.a, .{
626+ .name = self.a.dupe(u8, tc.name) catch "",
627+ .summary = callSummary(self.a, tc.name, tc.arguments),
628+ }) catch {};
577629 },
578630 .tool_call_start => |name| self.keepName(&self.writing_tool, name),
579631 .tool_output => |chunk| self.activity.feed(chunk),
@@ -621,7 +673,7 @@ const Tui = struct {
621673 self.separator = true;
622674 if (self.pending_calls.items.len > 0) {
623675 const call = self.pending_calls.orderedRemove(0);
624- self.commitLines(&.{call});
676+ self.commitLines(&.{.{ .text = std.fmt.allocPrint(self.s, "{s} {s}", .{ callHead(self.s, call.name), call.summary }) catch call.summary }});
625677 }
626678 const width = @max(self.term.width() - BODY_PREFIX.len, 1);
627679 const lines = resultLines(self.s, name, text, is_error);
@@ -641,7 +693,7 @@ const Tui = struct {
641693 fn flushCalls(self: *Tui) void {
642694 for (self.pending_calls.items) |call| {
643695 self.separator = true;
644- self.commitLines(&.{call});
696+ self.commitLines(&.{.{ .text = std.fmt.allocPrint(self.s, "{s} {s}", .{ callHead(self.s, call.name), call.summary }) catch call.summary }});
645697 }
646698 self.pending_calls.clearRetainingCapacity();
647699 }