diff options
| -rw-r--r-- | core/exec.zig | 21 | ||||
| -rw-r--r-- | core/panes.zig | 25 |
2 files changed, 41 insertions, 5 deletions
diff --git a/core/exec.zig b/core/exec.zig index c1e68970..611e3430 100644 --- a/core/exec.zig +++ b/core/exec.zig @@ -766,11 +766,7 @@ pub fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize { pane.command_done = false; pane.command_status = null; pane.command_pty = true; - // Its last run's errors go with it (SPEC §11). - var i: usize = 0; - while (i < p.messages.live_len) { - if (p.messages.live[i].pane == pane.serial and p.messages.live[i].kind == .@"error") p.messages.remove(i) else i += 1; - } + retireRuns(p, pane, line); pane.body.mode = .tty; // What the last program left the emulator in goes first: the // alternate screen left (only if it is there: leaving restores a @@ -794,6 +790,7 @@ pub fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize { return null; }; pane.command_from = winid(p, src); + retireRuns(p, pane, line); echoCommand(p, pane, line); layout.placeNew(p, from, from, free, .command); if (refusedPlacement(p, free)) { @@ -804,6 +801,20 @@ pub fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize { return free; } +/// A run of `line` starting in command pane `pane`: the errors of the +/// pane's last run go (SPEC §11), and those of an earlier run of the same +/// line in the same directory in another pane (one its job still prints +/// to, a leased one, another column's), whose next run this is. +fn retireRuns(p: *Pardes, pane: *const Pane, line: []const u8) void { + var i: usize = 0; + while (i < p.messages.live_len) { + const s = &p.messages.live[i]; + const ran = if (p.paneBySerial(s.pane)) |at| p.panes[at].? else null; + const again = if (ran) |r| if (r.command) |c| std.mem.eql(u8, c, line) and std.mem.eql(u8, r.cwdSlice(), pane.cwdSlice()) else false else false; + if (s.kind == .@"error" and (s.pane == pane.serial or again)) p.messages.remove(i) else i += 1; + } +} + /// Whether an open of a look or exec file holds `serial` from its own write /// (tree.Open.results): its client is reading that pane. pub fn leased(p: *const Pardes, serial: u32) bool { diff --git a/core/panes.zig b/core/panes.zig index 67cee035..51179df0 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -2023,6 +2023,31 @@ test "a command whose run fails naming places is an error of its pane, those pla try std.testing.expect(p.messages.headline() == null or p.messages.headline().?.kind != .@"error"); } +test "the same command line run again in the same directory takes its earlier run's error, whatever pane ran it (the failed one still printing a job's output, so not reused); another line's run, ending well, leaves it" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a command pane's terminal + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{}); + defer p.deinit(); + while (p.nextEffect()) |_| {} + p.setCwd(.at(0), "/tmp/pardes-cmd"); + _ = try pardes.Kind.open(p, 1, pardes.Kind.test_kind.of(p), "/tmp/pardes-cmd/pic.ppm", null); + const failed = exec.execute(p, 1, "make") orelse return error.NoCommandPane; + while (p.nextEffect()) |_| {} + p.update(.{ .output = .{ .pane = .at(failed), .bytes = "src/types.cc:7:11: error: did you mean to use '->'?\r\n" } }); + p.update(.{ .exited = .{ .pane = .at(failed), .status = 2 } }); + try std.testing.expectEqual(pardes.Messages.Kind.@"error", (p.messages.headline() orelse return error.NothingSaid).kind); + const other = exec.execute(p, 1, "make run") orelse return error.NoCommandPane; + while (p.nextEffect()) |_| {} + p.update(.{ .exited = .{ .pane = .at(other), .status = 0 } }); + try std.testing.expect(other != failed); + try std.testing.expectEqual(pardes.Messages.Kind.@"error", (p.messages.headline() orelse return error.NothingSaid).kind); + const again = exec.execute(p, 1, "make") orelse return error.NoCommandPane; + while (p.nextEffect()) |_| {} + try std.testing.expect(again != failed and again != other); + try std.testing.expect(p.messages.headline() == null or p.messages.headline().?.kind != .@"error"); + try std.testing.expect(p.messages.markOf(p.panes[failed].?) == null); +} + test "a failed run's places are read against the directory its tool says it is in: make's `Entering directory` (make -C, a make in a make) until its `Leaving directory`, as Emacs's compilation mode and Vim's %D and %X read them, those two lines no detail" { if (pardes.Term.ops == null) return error.SkipZigTest; // a command pane's terminal const gpa = std.testing.allocator; |
