summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/ninep/ctl.zig32
-rw-r--r--test/behaviour/look_and_exec.zig21
2 files changed, 41 insertions, 12 deletions
diff --git a/core/ninep/ctl.zig b/core/ninep/ctl.zig
index 6d78bc44..c99ec9ab 100644
--- a/core/ninep/ctl.zig
+++ b/core/ninep/ctl.zig
@@ -29,18 +29,27 @@ const E = tree.E;
// ---- which panes a command made or touched ----
+/// The serial of the pane in each slot, 0 for none.
const Serials = struct {
- list: [MAX_PANES]u32 = undefined,
- len: usize = 0,
+ of: [MAX_PANES]u32 = @splat(0),
fn snapshot(p: *Pardes) Serials {
var s: Serials = .{};
- for (p.panes) |slot| if (slot) |pane| {
- s.list[s.len] = pane.serial;
- s.len += 1;
+ for (p.panes, &s.of) |slot, *serial| if (slot) |pane| {
+ serial.* = pane.serial;
};
return s;
}
+
+ /// Whether the pane in slot `id` was made since the snapshot: it is in
+ /// a slot that held no pane or another, as a file made in an untouched
+ /// +New's place is under the +New's number (layout.takePane), and it
+ /// is not closing at the step's end, as that +New is under the number
+ /// it was given (Pardes.unplaced).
+ fn made(s: *const Serials, p: *const Pardes, id: usize) bool {
+ const pane = p.panes[id] orelse return false;
+ return pane.serial != s.of[id] and !p.unplaced.isSet(id);
+ }
};
fn noteResult(p: *Pardes, serial: u32) void {
@@ -89,14 +98,14 @@ pub fn run(p: *Pardes, id: usize, exec: bool, text: []const u8, in_tag: bool) vo
};
// A look that found nothing answers nothing, not the pane before it.
if (!exec and p.look_missed) return;
- const after = Serials.snapshot(p);
var created = false;
- for (after.list[0..after.len]) |serial| if (std.mem.indexOfScalar(u32, before.list[0..before.len], serial) == null) {
+ for (0..MAX_PANES) |k| if (before.made(p, k)) {
+ const made = p.panes[k].?;
// A query pane's +Preview is its query pane's: that answers.
- if (p.paneBySerial(serial)) |made| if (p.panes[made].?.file) |f| if (f.output) |o| if (o.from == .preview) continue;
+ if (made.file) |f| if (f.output) |o| if (o.from == .preview) continue;
// A look that made a +Search pane (a terminal's word)
// answers it: that is where the places it found are.
- noteResult(p, serial);
+ noteResult(p, made.serial);
created = true;
};
if (created) return;
@@ -598,10 +607,9 @@ pub fn runBuiltin(p: *Pardes, req: Req, id: usize, line: []const u8) ?Reply {
const context = if (p.panes[id]) |pane| pane.serial else 0;
const before = Serials.snapshot(p);
_ = exec_line.executeBuiltinLine(p, id, line);
- const after = Serials.snapshot(p);
var created = false;
- for (after.list[0..after.len]) |serial| if (std.mem.indexOfScalar(u32, before.list[0..before.len], serial) == null) {
- noteResult(p, serial);
+ for (0..MAX_PANES) |k| if (before.made(p, k)) {
+ noteResult(p, p.panes[k].?.serial);
created = true;
};
if (!created) noteResult(p, context);
diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig
index 251b6325..3e6137b1 100644
--- a/test/behaviour/look_and_exec.zig
+++ b/test/behaviour/look_and_exec.zig
@@ -813,3 +813,24 @@ test "look-and-exec: a reading pane that walks to another file is the same pane:
try std.testing.expect(std.mem.indexOf(u8, log, s.at("del {d} ", .{r})) == null);
try std.testing.expect(std.mem.indexOf(u8, try s.read("/recent"), s.at("{s}/a.txt", .{dir})) != null);
}
+
+test "look-and-exec: a look whose file takes an untouched +New's place (UX J1) reads back that pane, by the +New's number: a terminal's look into the +New under it, the root's from the +New itself" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = "a\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.txt", .data = "b\n" });
+ var buf: [4096]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)];
+ // As `pardes --tty` boots: a shell, an untouched +New under it.
+ var s = try Session.initTerm(std.testing.allocator);
+ defer s.deinit();
+ const shell = try s.focused();
+ for ([_][]const u8{ "a.txt", "b.txt" }, 0..) |name, i| {
+ try s.write(s.at("/pane/{d}/exec", .{shell}), "New\n");
+ const scratch = try s.focused();
+ try s.write(if (i == 0) s.at("/pane/{d}/look", .{shell}) else "/look", s.at("{s}/{s}\n", .{ dir, name }));
+ try s.expect(s.at("/pane/{d}/name", .{scratch}), s.at("{s}/{s}\n", .{ dir, name }));
+ try s.expect("/look", s.at("{d}\n", .{scratch}));
+ if (i == 0) try s.expect(s.at("/pane/{d}/look", .{shell}), s.at("{d}\n", .{scratch}));
+ }
+}