summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/daemon.zig30
-rw-r--r--src/gui/gui.zig2
-rw-r--r--src/tui/tui.zig12
3 files changed, 15 insertions, 29 deletions
diff --git a/src/daemon.zig b/src/daemon.zig
index eb2b7eed..fff7bbe5 100644
--- a/src/daemon.zig
+++ b/src/daemon.zig
@@ -608,38 +608,24 @@ pub fn hupOnStubDeath(on: bool) void {
pub fn tellStubDetached() void {
if (stub < 0) return;
hupOnStubDeath(false);
- tellDetached(stub);
+ tellStub(stub, "d{s}", .{name()});
stub = -1;
}
-/// The stub on `fd` told its terminal is detached (one of a session's
-/// several, views.zig), and the pipe let go.
-pub fn tellDetached(fd: c_int) void {
- if (fd < 0) return;
- var buf: [160]u8 = undefined;
- const said = std.fmt.bufPrint(&buf, "d{s}", .{name()}) catch "d";
- _ = libc.write(fd, said.ptr, said.len);
- _ = libc.close(fd);
-}
-
/// The session's end, `code` its exit status: the stub is told (and goes).
pub fn tellStubExit(code: u8) void {
- tellExit(stub, code);
+ tellStub(stub, "x{d}", .{code});
stub = -1;
}
-pub fn tellExit(fd: c_int, code: u8) void {
+/// The stub on `fd` told how its terminal's session went, what stubWait
+/// reads, and its pipe let go: `d<name>` detached (one of a session's
+/// several terminals, views.zig), `x<code>` exited, `r<why>` refused (an
+/// attach that came too late).
+pub fn tellStub(fd: c_int, comptime fmt: []const u8, args: anytype) void {
if (fd < 0) return;
- var buf: [8]u8 = undefined;
- const said = std.fmt.bufPrint(&buf, "x{d}", .{code}) catch "x1";
- _ = libc.write(fd, said.ptr, said.len);
- _ = libc.close(fd);
-}
-
-/// A terminal refused (an attach that came too late): its stub is told why.
-pub fn refuseStub(fd: c_int, why: []const u8) void {
var buf: [256]u8 = undefined;
- const said = std.fmt.bufPrint(&buf, "r{s}", .{why}) catch "r";
+ const said = std.fmt.bufPrint(&buf, fmt, args) catch fmt[0..1];
_ = libc.write(fd, said.ptr, said.len);
_ = libc.close(fd);
}
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index 33922286..7d77ed2a 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -4455,7 +4455,7 @@ fn deliverNote(ctx: *anyopaque, note: daemon.Note) void {
// A terminal for a window session: the daemon refuses that kind
// before it is sent, so only an old one's would be here.
if (a.tty >= 0) _ = libc.close(a.tty);
- if (a.stub >= 0) daemon.refuseStub(a.stub, "a window session takes no terminal");
+ if (a.stub >= 0) daemon.tellStub(a.stub, "r{s}", .{"a window session takes no terminal"});
if (a.tty < 0) q.push(.window);
},
.adopted => |a| {
diff --git a/src/tui/tui.zig b/src/tui/tui.zig
index a698abf7..dd0baf0b 100644
--- a/src/tui/tui.zig
+++ b/src/tui/tui.zig
@@ -1464,7 +1464,7 @@ const Screen = struct {
/// the terminal back).
fn sayDetached(sc: *Screen) void {
if (sc.primary) return daemon.tellStubDetached();
- daemon.tellDetached(sc.stub);
+ daemon.tellStub(sc.stub, "d{s}", .{daemon.name()});
sc.stub = -1;
}
@@ -1505,7 +1505,7 @@ const Screen = struct {
switch (how) {
.detach => sc.sayDetached(),
.exit => {
- daemon.tellExit(sc.stub, 0);
+ daemon.tellStub(sc.stub, "x{d}", .{0});
sc.stub = -1;
},
}
@@ -1787,7 +1787,7 @@ fn deliverNote(ctx: *anyopaque, note: daemon.Note) void {
const loop: *Loop = @ptrCast(@alignCast(ctx));
switch (note) {
.attach => |a| if (a.tty < 0) {
- if (a.stub >= 0) daemon.refuseStub(a.stub, "a terminal session takes a terminal");
+ if (a.stub >= 0) daemon.tellStub(a.stub, "r{s}", .{"a terminal session takes a terminal"});
} else loop.postEvent(.{ .attach = .{ .tty = a.tty, .stub = a.stub } }) catch {
_ = libc.close(a.tty);
_ = libc.close(a.stub);
@@ -2062,7 +2062,7 @@ const Shell = struct {
/// A terminal refused: its stub told why (a test's has none).
fn refuse(stub: posix.fd_t, why: []const u8) void {
- if (stub >= 0) daemon.refuseStub(stub, why);
+ if (stub >= 0) daemon.tellStub(stub, "r{s}", .{why});
}
fn adopt(ctx: ?*anyopaque, pane: u8) void {
@@ -2185,7 +2185,7 @@ const Shell = struct {
if (!pardes.views.isOpen(core, t.view) or s.terms[t.view] != null) {
if (t.primary) continue;
_ = libc.close(t.fd);
- if (t.stub >= 0) daemon.tellDetached(t.stub);
+ if (t.stub >= 0) daemon.tellStub(t.stub, "d{s}", .{daemon.name()});
continue;
}
const sc = if (t.primary) primary else extra: {
@@ -2204,7 +2204,7 @@ const Shell = struct {
break :extra sc;
} orelse {
_ = libc.close(t.fd);
- if (t.stub >= 0) daemon.tellDetached(t.stub);
+ if (t.stub >= 0) daemon.tellStub(t.stub, "d{s}", .{daemon.name()});
continue;
};
sc.feed.view = t.view;