diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-30 18:11:57 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-30 19:12:48 -0300 |
| commit | ef0fb2f9614bd6ad35991022d7be1cb40ca156ae (patch) | |
| tree | 0f814fd7832e875a680bb5cc6d024fb8facfa301 /src/terminal.zig | |
| parent | 782b1ef2e40b83e115c460f55e31c5c6bde2b62f (diff) | |
| download | pardes-ef0fb2f9614bd6ad35991022d7be1cb40ca156ae.tar.gz pardes-ef0fb2f9614bd6ad35991022d7be1cb40ca156ae.zip | |
terminal: an authority with screen-state replicas sizes a terminal after the step's unit, not inside it (resize_to, made by Peers.unit, null from `create` on): a client typing at another size than the last typist read history rows its replay held as holes, and the rows the session sent for them came in the new grid's numbering, which the replica cannot take, so its replay read blank text (the soak's local80 cell: jumps, njumps, jcur, pane 1.body at a b; fixer 2's H18, pane N.ovl); test/replicas.zig sizes them after its fill too; an in-process test reads the history in the step that resizes, with the session's order of flush, fill and unit, and another makes a terminal from 0xAA memory and finds no size waiting
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/terminal.zig')
| -rw-r--r-- | src/terminal.zig | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/terminal.zig b/src/terminal.zig index ade2311d..e9d628aa 100644 --- a/src/terminal.zig +++ b/src/terminal.zig @@ -172,6 +172,11 @@ pub const State = struct { /// step must hold them, so its authority sends the ones it does not /// before the step's unit (replica.Screens.fill). read: bool = false, + /// The size a step gave it, on an authority with screen-state replicas: + /// made after the step's unit (`resizeDeferred`), so that the rest of + /// the step reads the grid it had, as its replicas' replays do, and the + /// rows sent them for it (Screens.fill) are of that grid's numbering. + resize_to: ?struct { cols: u16, rows: u16 } = null, /// The emulator as its program has made it, for the replay digest /// (src/walk.zig): the active screen's text, how much history is above @@ -646,11 +651,30 @@ pub fn resizeGrid(pane: *Pane, gpa: std.mem.Allocator, cols: u16, rows: u16) voi }; // A replica's emulator is sized by its authority: the next delta says. if (pardes.tape.screenReplica()) return; + // ...and the authority's once the step's unit is out (a client typing + // at another size than the last typist's read history rows its replay + // held as holes, and the rows came renumbered, 2026-10-30). + if (pardes.tape.screenAuthority()) { + state.resize_to = .{ .cols = cols, .rows = rows }; + return; + } state.changes +%= 1; _ = gpa; state.vt.resize(state.gpa, .{ .cols = cols, .rows = rows }) catch {}; } +/// The sizes steps gave terminals (`resizeGrid`), made: between units, on an +/// authority with screen-state replicas (replica.Peers.unit). +pub fn resizeDeferred(p: *Pardes) void { + if (comptime !enabled) return; + for (p.panes) |slot| if (slot) |pane| if (pane.terminal) |state| if (state.resize_to) |size| { + state.resize_to = null; + state.changes +%= 1; + p.shell_rows.markStale(pane); + state.vt.resize(state.gpa, .{ .cols = size.cols, .rows = size.rows }) catch {}; + }; +} + /// DECSET 2004: the program wants its pastes bracketed. pub fn bracketedPaste(pane: *const Pane) bool { if (comptime !enabled) return false; @@ -888,6 +912,7 @@ pub fn create(gpa: std.mem.Allocator, cols: u16, rows: u16) !*Pane { state.reply_len = 0; state.changes = 0; state.read = false; + state.resize_to = null; // Every field its default (create leaves them what the heap had, which // a digest then reads: two replicas must agree, src/replica.zig). state.reply_dropped = 0; @@ -960,6 +985,40 @@ test "replay ownership is terminal-only and construction rolls back on allocatio try std.testing.checkAllAllocationFailures(std.testing.allocator, Case.run, .{true}); } +test "a terminal made fresh has no size waiting: one never resized keeps its grid when a unit is cut" { + if (comptime !enabled) return error.SkipZigTest; + // Fresh memory as a Debug build's allocator hands it out: 0xAA. A field + // `create` left unset read a size of 43690x43690 (fixer 2's, 2026-10-30). + const Filling = struct { + child: std.mem.Allocator, + fn alloc(ctx: *anyopaque, len: usize, a: std.mem.Alignment, ra: usize) ?[*]u8 { + const self: *@This() = @ptrCast(@alignCast(ctx)); + const ptr = self.child.rawAlloc(len, a, ra) orelse return null; + @memset(ptr[0..len], 0xAA); + return ptr; + } + fn resize(ctx: *anyopaque, buf: []u8, a: std.mem.Alignment, n: usize, ra: usize) bool { + const self: *@This() = @ptrCast(@alignCast(ctx)); + return self.child.rawResize(buf, a, n, ra); + } + fn remap(ctx: *anyopaque, buf: []u8, a: std.mem.Alignment, n: usize, ra: usize) ?[*]u8 { + const self: *@This() = @ptrCast(@alignCast(ctx)); + return self.child.rawRemap(buf, a, n, ra); + } + fn free(ctx: *anyopaque, buf: []u8, a: std.mem.Alignment, ra: usize) void { + const self: *@This() = @ptrCast(@alignCast(ctx)); + self.child.rawFree(buf, a, ra); + } + const vtable: std.mem.Allocator.VTable = .{ .alloc = alloc, .resize = resize, .remap = remap, .free = free }; + }; + var filling: Filling = .{ .child = std.testing.allocator }; + const gpa: std.mem.Allocator = .{ .ptr = &filling, .vtable = &Filling.vtable }; + const pane = try create(gpa, 40, 12); + defer gpa.destroy(pane); + defer deinitEmulator(pane, gpa); + try std.testing.expect(pane.terminal.?.resize_to == null); +} + test "document construction allocates only the pane and has inert terminal defaults" { var failing = std.testing.FailingAllocator.init(std.testing.allocator, .{ .fail_index = 1 }); const allocator = failing.allocator(); |
