summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 22:06:33 -0300
committerGabriel Schneider <[email protected]>2026-11-17 22:23:50 -0300
commit920110be4c597b4b93fc2d38179c09b335186253 (patch)
treefb5a3eaebb48b8c52ec0e23540e5065d940995d0 /src
parent7d10ad68b07a7bbab23fa8565d39183e4387c478 (diff)
downloadpardes-920110be4c597b4b93fc2d38179c09b335186253.tar.gz
pardes-920110be4c597b4b93fc2d38179c09b335186253.zip
words: a session with no frontend of its own is `detached` in the code, one word for what was `headless`, `parked`, `alone_unattended`, `Term.none` and `!attached()` (PARDES.md ruling 1): main.zig's and gui.zig's `headless` (run, runNative, localSession) are `detached`, tui.zig's `Term.none` is `Term.detached`, the window's `Shell.parked` (its Gui kept while detached) is `Shell.detached`, `replica.Peers.alone_unattended` is `Peers.detached`, and the terminal's `Shell.attached()` is `Shell.detached()`, its five callers and `watched` negated to match (a test's Shell with no screen is not detached, as it was attached); the tape's `headless`, a replica core that skips `render` and the host calls inside it (set on every client), is `skips_render`, its replay run named `skips-render` ("replay X: skips-render replica: N digests agree"), and the two that read that line follow (test/tty.zig's other-build replay, test/cross_replay.py); NOT renamed, a different fact: `Core.unattended` (detached AND no client: nobody looks), a watched field on the tape by index; names only, no logic moved; tui core-test 811/950 (139 skipped), shell-test 993/996, behaviour-test 269/273 (the four addon ABI tests the base fails) and the same with --replay, process-test 2 of 144 failed (lspcomplete and lspcompletemoved, the base's), replicas pass (checked/wrong 0), daemon.py main passes; gui frame corpus 77/77 byte-identical against mbase, unit-test 1582/1590 (the base's 8 failures)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'src')
-rw-r--r--src/gui/gui.zig32
-rw-r--r--src/main.zig12
-rw-r--r--src/replica.zig16
-rw-r--r--src/tape.zig26
-rw-r--r--src/tui/tui.zig29
5 files changed, 58 insertions, 57 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index 863bb81e..2df408e8 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -762,8 +762,8 @@ fn coverFrame(cover: []Cover, cols: u16, rows: u16, body_layers: []const pardes.
};
}
-pub fn run(init: std.process.Init, opts: pardes.Options, headless: bool) !void {
- return runNative(init, opts, headless, null);
+pub fn run(init: std.process.Init, opts: pardes.Options, detached: bool) !void {
+ return runNative(init, opts, detached, null);
}
/// `pardes-gui --attach=<socket>:<session>` (and `<host>:<session>`,
@@ -775,7 +775,7 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8,
const Dial = struct { path: []const u8, session: []const u8, far: bool };
-fn runNative(init: std.process.Init, opts_in: pardes.Options, headless: bool, dial: ?Dial) !void {
+fn runNative(init: std.process.Init, opts_in: pardes.Options, detached: bool, dial: ?Dial) !void {
const gpa = init.gpa;
const env = init.environ_map;
@@ -826,7 +826,7 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, headless: bool, di
if (surface_opacity) win_flags |= c.SDL_WINDOW_TRANSPARENT;
const reopen_flags = win_flags;
// `--detach`: a window never shown, closed once the session is up.
- if (headless) win_flags |= c.SDL_WINDOW_HIDDEN;
+ if (detached) win_flags |= c.SDL_WINDOW_HIDDEN;
// `--geometry=WxH[+X+Y]`, as X11 programs take it.
var want_w: c_int = 1120;
var want_h: c_int = 720;
@@ -964,7 +964,7 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, headless: bool, di
if (!test_mode and !c.SDL_SetWindowHitTest(window, hitTest, &g))
log.warn("SDL_SetWindowHitTest: {s}", .{c.SDL_GetError()});
if (dial) |to| return clientSession(init, &g, opts_in, test_mode, to);
- try localSession(init, &g, opts_in, test_mode, headless);
+ try localSession(init, &g, opts_in, test_mode, detached);
}
/// Detach: the window closed (and with it its swapchain or renderer); the
@@ -1004,7 +1004,7 @@ fn localSession(
g: *Gui,
opts_in: pardes.Options,
test_mode: bool,
- headless: bool,
+ detached: bool,
) !void {
const io = init.io;
const gpa = init.gpa;
@@ -1104,7 +1104,7 @@ fn localSession(
frame_capture_dir = if (std.c.getenv("PARDES_FRAMES_CAPTURE")) |dir| std.mem.span(dir) else null;
const host = shell.host();
core.host = host;
- shell.peers = .{ .gpa = gpa, .io = io, .name = daemon.name(), .wake = sdlWake, .alone_unattended = headless };
+ shell.peers = .{ .gpa = gpa, .io = io, .name = daemon.name(), .wake = sdlWake, .detached = detached };
defer shell.peers.deinit();
// Before the core goes: each client sees its link end.
defer shell.peers.dropAll(shell.core);
@@ -1127,7 +1127,7 @@ fn localSession(
_ = c.SDL_StartTextInput(g.window);
// An upgraded session's window, its view's again.
- if (upgrade.resumed) |*rec| if (!rec.fresh and !headless) shell.resumeWindow();
+ if (upgrade.resumed) |*rec| if (!rec.fresh and !detached) shell.resumeWindow();
if (test_mode) setStdinRaw() catch {};
shell.threads_ok = true;
@@ -1135,7 +1135,7 @@ fn localSession(
defer pardes.lsp.setStatusSink(null, null);
host_io.setExitWake(&queue, Queue.wakeForExit);
defer host_io.setExitWake(null, null);
- if (headless) {
+ if (detached) {
shell.closeTheWindow();
// Nothing else may wake the first wait.
daemon.watch(&shell, deliverNote);
@@ -2378,10 +2378,10 @@ fn pollGamepad(g: *Gui, in: *Input) void {
const Shell = struct {
core: *pardes.Pardes,
- /// The window's, while one is open; null while detached (`parked` has
+ /// The window's, while one is open; null while detached (`detached` has
/// it).
gui: ?*Gui = null,
- parked: ?*Gui = null,
+ detached: ?*Gui = null,
/// Shells a dead session left (Adopt), each waiting for the spawn of
/// the terminal pane made for it.
adoptions: host_io.Adoptions = .{},
@@ -2521,25 +2521,25 @@ const Shell = struct {
fn closeTheWindow(s: *Shell) void {
const g = s.gui orelse return;
closeWindow(g);
- s.parked = g;
+ s.detached = g;
s.gui = null;
s.presented = false;
s.surface = null;
// Its clients look at it still (Peers keeps it attended).
- s.peers.alone_unattended = true;
+ s.peers.detached = true;
s.core.unattended = s.peers.count() == 0;
daemon.setState(true);
}
fn openTheWindow(s: *Shell) void {
- const g = s.parked orelse return;
+ const g = s.detached orelse return;
if (!reopenWindow(g)) {
log.err("--attach: no window: {s}", .{c.SDL_GetError()});
return daemon.setState(true);
}
s.gui = g;
- s.parked = null;
- s.peers.alone_unattended = false;
+ s.detached = null;
+ s.peers.detached = false;
s.core.unattended = false;
s.core.needs_frame = true;
resetScroll(g);
diff --git a/src/main.zig b/src/main.zig
index 4a55695c..36d2da75 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -1519,19 +1519,19 @@ fn nativeMain(std_init: std.process.Init) !void {
opts.rows = 50;
}
const kind: daemon.Kind = if (pardes.platform == .gui) .gui else .tty;
- var term: @import("tui/tui.zig").Term = if (detach != null) .none else .open;
- var headless = detach != null;
+ var term: @import("tui/tui.zig").Term = if (detach != null) .detached else .open;
+ var detached = detach != null;
upgrade.remember(args);
if (upgrade.resumed) |*rec| {
// Close-on-exec again: a shell forked from here inherits none.
rec.closeOnExec(true);
opts.load_path = rec.dump;
- term = .none;
+ term = .detached;
for (rec.ttys[0..rec.nttys]) |t| if (t.primary) {
term = .{ .fd = .{ .fd = t.fd, .termios = t.termios } };
};
- headless = if (pardes.platform == .gui) !rec.window else rec.nttys == 0;
- daemon.resumeLink(rec.link, rec.stub, kind, opts.ninep_name, headless);
+ detached = if (pardes.platform == .gui) !rec.window else rec.nttys == 0;
+ daemon.resumeLink(rec.link, rec.stub, kind, opts.ninep_name, detached);
} else if (daemon.wanted()) {
if (detach != null or pardes.platform == .gui) {
_ = daemon.register(null, kind, opts.ninep_name, detach != null);
@@ -1574,7 +1574,7 @@ fn nativeMain(std_init: std.process.Init) !void {
},
else => return err,
},
- .gui => try @import("gui/gui.zig").run(init, opts, headless),
+ .gui => try @import("gui/gui.zig").run(init, opts, detached),
.macos => unreachable,
}
daemon.tellStubExit(0);
diff --git a/src/replica.zig b/src/replica.zig
index 32c8acd7..09746377 100644
--- a/src/replica.zig
+++ b/src/replica.zig
@@ -730,7 +730,7 @@ pub const Replica = struct {
pub fn initDump(gpa: Allocator, id: u16, view: u8, bytes: []const u8, opts: pardes.Options) !*Replica {
const r = try gpa.create(Replica);
r.* = .{ .gpa = gpa, .id = id, .view = view, .t = tape.memory(gpa), .guess = true };
- r.t.headless = true;
+ r.t.skips_render = true;
// Its terminals are the session's deltas (Peers sends them).
r.t.screen_state = true;
errdefer {
@@ -1847,9 +1847,9 @@ pub const Peers = struct {
/// Wakes the session's loop (its wait for input) from a reader.
wake_ctx: ?*anyopaque = null,
wake: ?*const fn (?*anyopaque) void = null,
- /// What the session would be with no client: unattended without a
- /// terminal of its own (the host says).
- alone_unattended: bool = false,
+ /// No frontend of its own (the host says): with no client either, the
+ /// session is unattended.
+ detached: bool = false,
/// The worst a join cost the session's step, and the last one's dump.
join_ns: u64 = 0,
each_join: std.ArrayListUnmanaged(u64) = .empty,
@@ -2044,7 +2044,7 @@ pub const Peers = struct {
// its view not kept yet, and takes a new one.
const back = if (joining.view) |v| core.rejoinView(v) else false;
const k = (if (back) joining.view else core.openView()) orelse {
- core.unattended = ps.count() == 0 and ps.alone_unattended;
+ core.unattended = ps.count() == 0 and ps.detached;
if (ps.count() == 0) ps.stop(core);
return daemon.refuseReplica(fd, "that session has as many views as it takes");
};
@@ -2117,7 +2117,7 @@ pub const Peers = struct {
ps.screens.dropPeer(peer.sid);
core.undrawn &= ~(@as(u8, 1) << @intCast(peer.view));
ps.closeViewOf(core, peer, peer.again);
- if (ps.count() == 0) core.unattended = ps.alone_unattended;
+ if (ps.count() == 0) core.unattended = ps.detached;
ps.seq += 1;
ps.unit(0, ps.seq);
ps.letGo(peer);
@@ -2129,7 +2129,7 @@ pub const Peers = struct {
/// session no one else watches leaves the session its layout, for a
/// client that comes after to find.
fn closeViewOf(ps: *Peers, core: *Pardes, peer: *Peer, again: bool) void {
- if (again) core.awayView(peer.view) else if (ps.count() == 0 and ps.alone_unattended) core.leaveView(peer.view) else core.closeView(peer.view);
+ if (again) core.awayView(peer.view) else if (ps.count() == 0 and ps.detached) core.leaveView(peer.view) else core.closeView(peer.view);
}
/// Its threads ended and joined, its link closed.
@@ -2265,7 +2265,7 @@ pub const Peers = struct {
};
ps.inbox.clearRetainingCapacity();
ps.lock.unlock(ps.io);
- core.unattended = ps.alone_unattended;
+ core.unattended = ps.detached;
}
pub fn deinit(ps: *Peers) void {
diff --git a/src/tape.zig b/src/tape.zig
index fd5b4b85..eaae601e 100644
--- a/src/tape.zig
+++ b/src/tape.zig
@@ -212,7 +212,7 @@ pub const Tape = struct {
arena: std.heap.ArenaAllocator,
last_ret: walk.Reader = .{ .bytes = &.{} },
mask: u64 = 0,
- headless: bool = false,
+ skips_render: bool = false,
digests: u64 = 0,
diverged: ?[]const u8 = null,
/// The input being applied, for a divergence's report.
@@ -338,7 +338,7 @@ pub const Tape = struct {
t.mask = mask;
t.vtable = .{};
inline for (host_fns, 0..) |f, i| if (mask & (@as(u64, 1) << i) != 0 or
- (t.headless and comptime std.mem.eql(u8, f, "watched")))
+ (t.skips_render and comptime std.mem.eql(u8, f, "watched")))
{
@field(t.vtable, f) = &Wrap(i).f;
};
@@ -399,7 +399,7 @@ pub const Tape = struct {
t.diverged = std.fmt.allocPrint(t.gpa, why ++ " (tape byte {d}, in {s})", args ++ .{ t.in.at, t.applying }) catch why;
}
- /// A host call the headless replica does not make (it draws no frame,
+ /// A host call a replica that skips render does not make (it draws no frame,
/// so presents none): what the host told the core inside it (what it
/// presented, `presented`) is applied all the
/// same, the host's own calls below it stepped over.
@@ -417,7 +417,7 @@ pub const Tape = struct {
}
}
- /// Over a call the replica does not make (the headless one's present),
+ /// Over a call the replica does not make (a present, in one that skips render),
/// what was applied inside it too.
fn skip(t: *Tape) void {
var depth: usize = 1;
@@ -432,7 +432,7 @@ pub const Tape = struct {
}
/// The records of an input up to its end: what was applied inside it,
- /// as it was; the headless replica steps over the host calls it did
+ /// as it was; a replica that skips render steps over the host calls it did
/// not make.
fn finishInput(t: *Tape) void {
while (t.diverged == null) {
@@ -441,7 +441,7 @@ pub const Tape = struct {
switch (kind) {
.done => return,
.set => t.applySet(&rec.payload),
- .host => if (t.headless) t.skipHost() else return t.diverge("the core did not make the host call {d} the tape has", .{std.mem.bytesToValue(u16, rec.payload.bytes[0..2])}),
+ .host => if (t.skips_render) t.skipHost() else return t.diverge("the core did not make the host call {d} the tape has", .{std.mem.bytesToValue(u16, rec.payload.bytes[0..2])}),
.input => t.apply(&rec.payload),
.digest => t.check(rec.payload.bytes),
.ret => return t.diverge("the core's input ended before the recorded one", .{}),
@@ -607,7 +607,7 @@ pub const Tape = struct {
.perform => |e| p.perform(e),
.next_effect => _ = p.nextEffect(),
.advance => |now| p.advance(now),
- .render => if (t.headless) return t.skip() else {
+ .render => if (t.skips_render) return t.skip() else {
_ = p.frame_arena.reset(.retain_capacity);
_ = p.render(p.frame_arena.allocator()) catch {};
},
@@ -809,7 +809,7 @@ fn hostCall(comptime i: usize, comptime R: type, ctx: ?*anyopaque, args: anytype
};
if (t.replay) {
// A replica that never draws is never watched: it asks no one.
- if (comptime std.mem.eql(u8, name, "watched")) if (t.headless) return false;
+ if (comptime std.mem.eql(u8, name, "watched")) if (t.skips_render) return false;
if (!t.expectHost(i, name)) return std.mem.zeroes(R);
var ret = t.last_ret;
if (R == ?[]const u8) {
@@ -1281,15 +1281,15 @@ pub fn replayMain(path: []const u8) u8 {
/// digest and dumped to its bytes again: true when none diverged. An
/// in-process session's tape too (test/session.zig's replayTape).
pub fn replayBytes(gpa: std.mem.Allocator, bytes: []const u8, path: []const u8, dump: bool) bool {
- const runs = [_]struct { name: []const u8, headless: bool }{
- .{ .name = "first", .headless = false },
+ const runs = [_]struct { name: []const u8, skips_render: bool }{
+ .{ .name = "first", .skips_render = false },
// The first replica's memory is still held: this one's lies elsewhere.
- .{ .name = "second", .headless = false },
- .{ .name = "headless", .headless = true },
+ .{ .name = "second", .skips_render = false },
+ .{ .name = "skips-render", .skips_render = true },
};
var failed = false;
for (runs) |run| {
- var t: Tape = .{ .gpa = gpa, .replay = true, .headless = run.headless, .scratch = .init(gpa), .arena = .init(gpa) };
+ var t: Tape = .{ .gpa = gpa, .replay = true, .skips_render = run.skips_render, .scratch = .init(gpa), .arena = .init(gpa) };
t.dump_check = std.mem.eql(u8, run.name, "first") and dump;
on = &t;
defer on = null;
diff --git a/src/tui/tui.zig b/src/tui/tui.zig
index 7aebeb7a..1c6a3b7f 100644
--- a/src/tui/tui.zig
+++ b/src/tui/tui.zig
@@ -582,10 +582,10 @@ fn surfaceHasKittyKey(surface: *const pardes.Surface, key: u64) bool {
/// Where a session's terminal comes from: /dev/tty, as a plain `pardes`
/// opens it; one open already (a session forked off its stub,
-/// daemon.forkSession); or none, until one is attached (`--detach`).
+/// daemon.forkSession); or none, detached until one is attached (`--detach`).
/// The terminal a session starts on: /dev/tty, one its stub opened (an
/// upgraded session's is raw already, `termios` the cooked one), or none.
-pub const Term = union(enum) { open, fd: struct { fd: posix.fd_t, termios: ?posix.termios = null }, none };
+pub const Term = union(enum) { open, fd: struct { fd: posix.fd_t, termios: ?posix.termios = null }, detached };
pub fn run(init: std.process.Init, opts: pardes.Options, term: Term) !void {
const io = init.io;
@@ -608,7 +608,7 @@ pub fn run(init: std.process.Init, opts: pardes.Options, term: Term) !void {
switch (term) {
.open => try screen.enter(try vaxis.Tty.init(io, &tty_buf)),
.fd => |t| try screen.enter(try Screen.ttyOn(io, &tty_buf, t.fd, t.termios)),
- .none => {},
+ .detached => {},
}
defer screen.leave();
@@ -1076,7 +1076,7 @@ fn localSession(
// An upgraded session's terminals, its own again.
if (comptime !builtin.is_test) if (upgrade.resumed) |*rec| sh.resumeTerminals(rec);
// Nobody to see it, and nobody to size it: `size` sets it (ctl.zig).
- sh.setAttended(sh.attached());
+ sh.setAttended(!sh.detached());
while (core.nextEffect()) |effect| core.perform(effect);
// ...and its shells, once a fresh session's own has a directory to
// adopt them in.
@@ -1130,7 +1130,7 @@ fn localSession(
if (live.on) clearNativeImages(&live.kitty, &live.vx, &live.tty);
nc.view().frontend.native_images = live.on and live.vx.caps.kitty_graphics;
nc.unattended = !live.on;
- sh.peers.alone_unattended = !live.on;
+ sh.peers.detached = !live.on;
if (fs) |f| f.reset(nc);
core.deinit();
core = nc;
@@ -1264,7 +1264,7 @@ const Shell = struct {
/// Whether anyone looks at the session: a terminal here, or a replica
/// client (Peers keeps it attended while one is there).
fn setAttended(s: *Shell, on: bool) void {
- s.peers.alone_unattended = !on;
+ s.peers.detached = !on;
s.core.unattended = !on and s.peers.count() == 0;
}
@@ -1333,14 +1333,15 @@ const Shell = struct {
return if (s.core.live == s.own) s.screen else null;
}
- fn attached(s: *const Shell) bool {
- const screen = s.screen orelse return true;
- return screen.on;
+ /// No terminal of its own (a test's, with none at all, is not detached).
+ fn detached(s: *const Shell) bool {
+ const screen = s.screen orelse return false;
+ return !screen.on;
}
/// Drawn only while a terminal shows it.
fn watched(ctx: ?*anyopaque) bool {
- return of(ctx).attached();
+ return !of(ctx).detached();
}
/// Detach: the terminal put back and let go, the stub told (it ends,
@@ -1349,7 +1350,7 @@ const Shell = struct {
const s = of(ctx);
// A replica client's: its link ends.
if (s.peers.detach(s.core.live)) return;
- if (!s.attached()) return s.core.reportFailure(s.core.view().active, "Detach: no terminal is attached");
+ if (s.detached()) return s.core.reportFailure(s.core.view().active, "Detach: no terminal is attached");
if (!daemon.kept()) return s.core.reportFailure(s.core.view().active, "Detach: no pardes daemon keeps this session (it is its terminal's job)");
s.leaveTerminal();
}
@@ -1538,7 +1539,7 @@ const Shell = struct {
if (s.moving()) wait = 1;
// Detached, nobody's key dismisses a message: they go on the clock
// (the pump's, after this wait), which wakes it.
- if (!s.attached()) {
+ if (s.detached()) {
for (s.core.panes) |slot| if (slot) |pane| if (pane.msg_len > 0) {
wait = if (wait == 0) 100 else @min(wait, 100);
break;
@@ -1714,7 +1715,7 @@ const Shell = struct {
// waits on it) is not started yet: started here.
daemon.watch(s.loop, deliverNote);
if (daemon.kept()) {
- if (s.attached()) s.leaveTerminal();
+ if (!s.detached()) s.leaveTerminal();
return true;
}
core.quit = true;
@@ -1744,7 +1745,7 @@ const Shell = struct {
s.feed(.pointer_leave);
s.feed(.{ .focus = false });
},
- .winsize => |ws| if (s.attached()) s.resized(s.screen, ws),
+ .winsize => |ws| if (!s.detached()) s.resized(s.screen, ws),
.pty_read => |pr| {
tookRead(s.io, pr.id);
s.output_seen = true;