summaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/main.zig b/src/main.zig
index 5dd6a8e6..e998accc 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -563,16 +563,23 @@ fn nativeMain(init: std.process.Init) !void {
// process is a shell that outlived its editor (a daemon started from a
// pane, a stale environment carried into a new terminal), which is not
// nested at all.
- const owner = std.mem.span(std.c.getenv("PARDES_PID") orelse break :forwarding);
- const pid = std.fmt.parseInt(std.c.pid_t, owner, 10) catch break :forwarding;
- if (pid <= 0 or std.c.kill(pid, @enumFromInt(0)) != 0) break :forwarding;
+ // `--wait` with only $PARDES_9P (a script or agent that talks to a
+ // session from outside its panes, EDITOR='pardes --wait') is asked
+ // of that session too: what it waits on is a pane there.
+ const outside = wait and std.c.getenv("PARDES_PID") == null and std.c.getenv("PARDES_9P") != null;
+ if (!outside) {
+ const owner = std.mem.span(std.c.getenv("PARDES_PID") orelse break :forwarding);
+ const pid = std.fmt.parseInt(std.c.pid_t, owner, 10) catch break :forwarding;
+ if (pid <= 0 or std.c.kill(pid, @enumFromInt(0)) != 0) break :forwarding;
+ }
// Can I reach it? That is the other two, and it is a separate answer.
const Parent = struct { dial: []const u8, serial: u32 };
const found: ?Parent = reaching: {
const dial = std.mem.span(std.c.getenv("PARDES_9P") orelse break :reaching null);
ninep_io.Client.validateDial(dial) catch break :reaching null;
- const pane_text = std.mem.span(std.c.getenv("PARDES_PANE") orelse break :reaching null);
+ // No pane of its own (`outside`): the session's root look, 0.
+ const pane_text = std.mem.span(std.c.getenv("PARDES_PANE") orelse if (outside) break :reaching .{ .dial = dial, .serial = 0 } else break :reaching null);
for (pane_text) |byte| if (!std.ascii.isDigit(byte)) break :reaching null;
const serial = std.fmt.parseInt(u32, pane_text, 10) catch break :reaching null;
if (serial == 0) break :reaching null;
@@ -602,7 +609,7 @@ fn nativeMain(init: std.process.Init) !void {
// The pane's `look` file: one line, and the line is the clicked text
// itself, which is what a right click in that pane would have been.
var look_buf: [64]u8 = undefined;
- const look = try std.fmt.bufPrint(&look_buf, "/pane/{d}/look", .{parent.serial});
+ const look = if (parent.serial == 0) "/look" else try std.fmt.bufPrint(&look_buf, "/pane/{d}/look", .{parent.serial});
// `pardes -`: stdin read to its end, a +Pager pane of the session
// made of it (as acme's `B` has no stdin, through pane/new, a name
// and the body), and back at once: the PAGER a pane's shell gets.
@@ -613,6 +620,9 @@ fn nativeMain(init: std.process.Init) !void {
pageInto(init.io, arena, parent.dial, text);
return;
};
+ // From outside the session's panes there is no pane to say it is
+ // nested in: `--wait` with no file opens nothing there.
+ if (parent.serial == 0 and positional == null) break :forwarding;
const typed_word = positional orelse {
var tag_buf: [64]u8 = undefined;
const tag = try std.fmt.bufPrint(&tag_buf, "/pane/{d}/tag", .{parent.serial});