diff options
| -rw-r--r-- | core/panes.zig | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/core/panes.zig b/core/panes.zig index 6fcb15b6..fe127acd 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -1071,6 +1071,14 @@ pub const Pane = struct { } var buf: [16]u8 = undefined; const code = if (status) |n| std.fmt.bufPrint(&buf, "{d}", .{n}) catch unreachable else "?"; // an exit status fits 16 + // A failed run's last rows, read before its `exit N` goes under + // them: a report's places are at its end, and its detail is the + // tool's lines, not the run's status (UX F2). + const rows: ?[]const []const u8 = if (status == 0) null else if (pane.terminal) |state| read: { + const grid = Term.grid(state); + const first = grid.total -| 400; + break :read Term.editRows(state, p.scratch.allocator(), first, grid.total - first) catch null; + } else null; var said: pardes.Kind.Buf(32) = .{}; const lead = if (Term.grid(pane.terminal).cursor_x != 0) "\r\n" else ""; pane.feedOutput(p, said.print("{s}exit {s}\r\n", .{ lead, code })); @@ -1078,21 +1086,17 @@ pub const Pane = struct { p.needs_frame = true; // A failed run whose report names places (a compiler's // `path:line:col: error: ...`): an error of this pane, the places - // its words, the rows after its first its detail (SPEC §10.2). Its - // last rows only: a report's places are at its end. - if (status != 0) if (pane.terminal) |state| report: { - const grid = Term.grid(state); - const first = grid.total -| 400; - const rows = Term.editRows(state, p.scratch.allocator(), first, grid.total - first) catch break :report; + // its words, the rows after its first its detail (SPEC §10.2). + if (rows) |report_rows| report: { var found: pardes.Messages.Said = .{}; - if (pardes.Messages.readPlaces(&found, pane.cwdSlice(), rows) == 0) break :report; + if (pardes.Messages.readPlaces(&found, pane.cwdSlice(), report_rows) == 0) break :report; var words: pardes.Kind.Buf(32) = .{}; const kept = pardes.Messages.say(p, .@"error", id, words.print("exit {s}", .{code})); kept.places = found.places; kept.places_len = found.places_len; kept.detail = found.detail; kept.detail_len = found.detail_len; - }; + } } }; @@ -1981,6 +1985,9 @@ test "a command whose run fails naming places is an error of its pane, those pla try std.testing.expectEqual(@as(u8, 1), said.places_len); try std.testing.expectEqualStrings("/tmp/pardes-cmd/core/pick.zig", said.places[0].path.slice()); try std.testing.expectEqualStrings(" const best = rank(q, name, 3);", said.detail[0].slice()); + // The tool's lines alone: pardes's own `exit 1` under them is the run's + // status, in the command's tag and on the notice row (UX F2). + try std.testing.expectEqual(@as(u8, 1), said.detail_len); var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); const s = try p.render(frame.allocator()); |
