summaryrefslogtreecommitdiff
path: root/src/tty/tty.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-30 01:51:44 -0300
committerGabriel Schneider <[email protected]>2026-10-30 03:13:15 -0300
commit6118ad214bb74744e7b38004b34e4487a6635be1 (patch)
tree16c5f4c3d0e3df31d7a7ffab2a9726f619be43fd /src/tty/tty.zig
parentfdf74e199de7d0fc648f912875323f3dc920ffc2 (diff)
downloadpardes-6118ad214bb74744e7b38004b34e4487a6635be1.tar.gz
pardes-6118ad214bb74744e7b38004b34e4487a6635be1.zip
replica clients' terminals as screen state: the session's Peers keep a Screens (rterm's), a peer each: the rows a pump's steps read before its unit, the deltas after it, and before each client input's step, the rows it read before its unit; a joiner's terminals afresh after its dump; acks, rows asked and resets from the client (0x04) taken at the boundary; units carry no pty bytes and a word of digest
The client applies a delta or rows (0x06) in stream order and asks for the rows it shows and lacks after each frame; its dump's emulators are loaded on the C heap (walk.zig `.alloc` of a pane's `terminal`, dump.zig `terminal_gpa`), as `terminal.create` makes a screen replica's. Its load checked under its own tape (no emulator in the digest). tty.zig: with replica clients, a wait takes one step of a person's input and none after a pty's output (`split`): the next is held for the next wait, so a step reads the terminals as the deltas after each unit bring them. Screens: `dropPeer` (clients come and go), its numbers reused. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/tty/tty.zig')
-rw-r--r--src/tty/tty.zig87
1 files changed, 72 insertions, 15 deletions
diff --git a/src/tty/tty.zig b/src/tty/tty.zig
index 43994645..2eafc785 100644
--- a/src/tty/tty.zig
+++ b/src/tty/tty.zig
@@ -158,6 +158,8 @@ pub const Command = struct {
replica_mail,
/// A replica client's: what the session streamed (replica.Client).
unit: []u8,
+ /// ...a terminal's delta or rows, before the units after it.
+ screen: []u8,
/// The session's digest, asked by PARDES_REPLICA_CHECK.
checked: u64,
link_gone,
@@ -1353,6 +1355,12 @@ const Remote = struct {
core.present_skipped = skipped;
core.needs_frame = needs;
c.dirty = false;
+ // The history rows it shows and does not hold (a scroll back),
+ // asked for: blank until they come.
+ while (c.r.screenRequest()) |req| if (!replica.sendScreen(c.fd, req)) {
+ c.quit = true;
+ break;
+ };
}
};
@@ -1371,10 +1379,12 @@ fn linkReader(gpa: std.mem.Allocator, fd: posix.fd_t, rest: *replica.Framer, loo
const d = (wire.decodeServer(tag, payload) catch return false).check;
l.postEvent(.{ .checked = d }) catch {};
},
+ .screen => {
+ const bytes = std.heap.c_allocator.dupe(u8, payload) catch return false;
+ l.postEvent(.{ .screen = bytes }) catch std.heap.c_allocator.free(bytes);
+ },
.refused => return false,
- // ponytail: a terminal's delta (rterm's, src/screen_state.zig)
- // applies here once terminals cross as screens.
- .screen, .pong, .welcome, .dump => {},
+ .pong, .welcome, .dump => {},
}
return true;
}
@@ -1517,7 +1527,7 @@ pub fn remote(init: std.process.Init, opts: pardes.Options, path: []const u8, se
_ = libc.shutdown(joined.fd, 2);
while (true) {
while (loop.tryEvent() catch null) |ev| switch (ev) {
- .unit => |b| std.heap.c_allocator.free(b),
+ .unit, .screen => |b| std.heap.c_allocator.free(b),
.paste => |b| gpa.free(@constCast(b)),
else => {},
};
@@ -2024,6 +2034,10 @@ const Shell = struct {
/// speculations stand on (a replica takes such a unit as is).
mail_only: bool = false,
waited: bool = false,
+ /// This wait's steps so far, and the input held for the next (`split`).
+ took_input: bool = false,
+ took_output: bool = false,
+ held: ?@TypeOf(Command.value) = null,
/// This process a replica client of a session elsewhere (`remote`):
/// its inputs go to the replica, never straight to the core.
remote: ?*Remote = null,
@@ -2468,6 +2482,8 @@ const Shell = struct {
}
s.input_seen = false;
s.output_seen = false;
+ s.took_input = false;
+ s.took_output = false;
s.mail_only = true;
defer s.waited = true;
// Paced, what is not an input (a frame's ack, a pty's output) is
@@ -2500,25 +2516,32 @@ const Shell = struct {
fn waitOnce(s: *Shell, wait: u32) void {
var batch: usize = 0;
- if (wait != 0) {
- // A virtual clock moves a frame a wake while anything moves
- // continuously (the glide), as the real one would.
- s.wake_to = s.core.nextWake() orelse if (s.core.continuous()) s.core.now_ns + pardes.animation.frame_ns else 0;
- requestWake(s.io, wait);
- }
- pardes.turn.rest();
- const first = s.loop.nextEvent() catch {
+ const first = if (s.held) |held| held: {
+ s.held = null;
+ break :held held;
+ } else next: {
+ if (wait != 0) {
+ // A virtual clock moves a frame a wake while anything moves
+ // continuously (the glide), as the real one would.
+ s.wake_to = s.core.nextWake() orelse if (s.core.continuous()) s.core.now_ns + pardes.animation.frame_ns else 0;
+ requestWake(s.io, wait);
+ }
+ pardes.turn.rest();
+ const got = s.loop.nextEvent() catch {
+ pardes.turn.wake();
+ s.core.quit = true;
+ return s.reloadWatched();
+ };
pardes.turn.wake();
- s.core.quit = true;
- return s.reloadWatched();
+ break :next got;
};
- pardes.turn.wake();
batch = 1;
// A run of queued motions is one move to its last cell: each would
// otherwise redo hover and selection work the next one undoes.
var motion: ?@TypeOf(Command.value) = null;
var ev = first;
while (true) {
+ if (s.split(ev)) break;
if (ev == .mouse and (ev.mouse.type == .motion or ev.mouse.type == .drag)) {
if (motion) |m| if (m.mouse.button != ev.mouse.button or m.mouse.type != ev.mouse.type or
@as(u3, @bitCast(m.mouse.mods)) != @as(u3, @bitCast(ev.mouse.mods)))
@@ -2542,6 +2565,31 @@ const Shell = struct {
s.reloadWatched();
}
+ /// With replica clients, a wait (one pump, one unit) takes one step of
+ /// a person's input, and none after a pty's output: a step reads the
+ /// terminals as the clients' deltas bring them, sent after each unit
+ /// (docs/next-daemon.md, part B terminal notes). One that must wait is
+ /// held for the next. Whether `ev` is.
+ fn split(s: *Shell, ev: @TypeOf(Command.value)) bool {
+ if (!s.peers.recording) return false;
+ switch (ev) {
+ .pty_read => {
+ s.took_output = true;
+ return false;
+ },
+ .key_press => if (s.in_paste) return false,
+ .mouse, .paste, .paste_end, .winsize, .focus_in, .focus_out => {},
+ else => return false,
+ }
+ if (s.took_output or s.took_input) {
+ s.held = ev;
+ s.input_seen = true;
+ return true;
+ }
+ s.took_input = true;
+ return false;
+ }
+
fn apply(s: *Shell, event: @TypeOf(Command.value)) bool {
const core = s.core;
const tz_event = tracy.zone(@src(), "event");
@@ -2626,6 +2674,15 @@ const Shell = struct {
}
std.heap.c_allocator.free(bytes);
},
+ .screen => |bytes| {
+ if (s.remote) |c| {
+ if (c.r.screen(bytes)) |reply| if (!replica.sendScreen(c.fd, reply)) {
+ c.quit = true;
+ };
+ c.dirty = true;
+ }
+ std.heap.c_allocator.free(bytes);
+ },
.checked => |d| if (s.remote) |c| c.checked(d),
.link_gone => if (s.remote) |c| {
c.quit = true;