@@ -11,9 +11,8 @@ fn callHead(a: std.mem.Allocator, name: []const u8) []const u8 {
1111 return styles.accent(a, std.fmt.allocPrint(a, "{s}", .{name}) catch "tool");
1212 }
1313
14-pub fn diffHead(a: std.mem.Allocator, name: []const u8, path: []const u8) []const u8 {
15- const head = callHead(a, std.fmt.allocPrint(a, "{s} diff", .{name}) catch name);
16- return std.fmt.allocPrint(a, "{s} {s}", .{ head, path }) catch path;
14+pub fn diffHead(a: std.mem.Allocator, path: []const u8) []const u8 {
15+ return std.fmt.allocPrint(a, "{s} {s}", .{ callHead(a, "diff"), path }) catch path;
1716 }
1817
1918 pub fn relativize(cwd: []const u8, path: []const u8) []const u8 {
@@ -25,11 +24,19 @@ pub fn relativize(cwd: []const u8, path: []const u8) []const u8 {
2524 return rest[1..];
2625 }
2726
27+/// The first line of a command; more lines are dropped, not drawn.
28+fn preview(a: std.mem.Allocator, command: []const u8) []const u8 {
29+ const end = std.mem.indexOfScalar(u8, command, '\n') orelse return command;
30+ if (std.mem.indexOfNone(u8, command[end..], " \t\r\n") == null) return command[0..end];
31+ const first = std.mem.trimEnd(u8, command[0..end], " \t\r");
32+ return std.fmt.allocPrint(a, "{s} …", .{first}) catch first;
33+}
34+
2835 pub fn callSummary(a: std.mem.Allocator, name: []const u8, args_json: []const u8) []const u8 {
2936 const parsed = std.json.parseFromSliceLeaky(std.json.Value, a, args_json, .{}) catch return args_json;
3037 if (parsed == .object) {
3138 if (std.mem.eql(u8, name, "bash")) {
32- if (parsed.object.get("command")) |c| if (c == .string) return c.string;
39+ if (parsed.object.get("command")) |c| if (c == .string) return preview(a, c.string);
3340 }
3441 if (std.mem.eql(u8, name, "edit") or std.mem.eql(u8, name, "read")) {
3542 if (parsed.object.get("path")) |p| if (p == .string) return p.string;
@@ -38,21 +45,12 @@ pub fn callSummary(a: std.mem.Allocator, name: []const u8, args_json: []const u8
3845 return args_json;
3946 }
4047
41-pub fn callBody(a: std.mem.Allocator, name: []const u8, summary: []const u8, width: usize) []const []const u8 {
42- const head = callHead(a, name);
43- const body = summary;
44- var rows: std.ArrayList([]const u8) = .empty;
45- var it = std.mem.splitScalar(u8, body, '\n');
46- var i: usize = 0;
47- while (it.next()) |line| : (i += 1) {
48- const args = if (line.len == 0) line else styles.styledWith(a, .{ .bold = true }, line);
49- const text = if (i == 0)
50- std.fmt.allocPrint(a, "{s} {s}", .{ head, args }) catch line
51- else
52- args;
53- rows.append(a, text) catch {};
54- }
55- return render.elide(a, rows.items, width);
48+/// One line: the tool name and a clipped preview of its arguments.
49+pub fn callLine(a: std.mem.Allocator, name: []const u8, summary: []const u8, width: usize) []const u8 {
50+ const head = std.fmt.allocPrint(a, "{s} ", .{callHead(a, name)}) catch return summary;
51+ const room = width -| render.displayWidth(head);
52+ const args = styles.styledWith(a, .{ .bold = true }, render.clip(a, render.expandTabs(a, summary, 4), room));
53+ return std.fmt.allocPrint(a, "{s}{s}", .{ head, args }) catch summary;
5654 }
5755
5856 pub const Result = struct {