diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-22 03:03:55 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-22 10:31:04 -0300 |
| commit | 9158de5d50831e115e14e2ed502300ee8c1d9930 (patch) | |
| tree | 2b5e60569307e02d82b19bd419279392a6da257b /test/replicas.zig | |
| parent | 70c9e3fbf9cdc7139b4da0142f3a44741a7e1491 (diff) | |
| download | pardes-9158de5d50831e115e14e2ed502300ee8c1d9930.tar.gz pardes-9158de5d50831e115e14e2ed502300ee8c1d9930.zip | |
term: screen_state.zig deleted, and the terminal module's side of the delta road (the old road's deletion, piece 5 of 8): core/term/screen_state.zig (1,213 lines: the encoder, tracks, peers' flights, a replica's apply and holes, its own soak and four tests) goes whole; core/term/terminal.zig loses `encode`/`encodeRows`/`encoder`/`encoderFree`/`track`/`untrack`/`replica`/`replicaFree`/`replicaTop`/`missing`/`apply`/`applyRows`/`shown`/`blank`, `takeMarks` (`marksOf` stays, private: the tests compare two terminals by it), the State's `changes` (a version's counter for the tracks), `read` with `markRead`/`wasRead`/`clearRead` (the rows a step read, for the fills), and `resize_to` with `resizeDeferred` and `resize`'s `later` (screen state's authority sized its terminals after a step's unit); abi/term.zig loses the `Encoder`/`Track`/`Replica` handles, `flight_bound`, `Peer`, `Applied` and those entries of `Ops` (and `dumpScreen`, which nothing in the core called); core/Term.zig its wrappers; core/term/term.zig its ops, its handle map and its `screen_state` export; core/panes.zig its `resizeDeferred` and resizes now (its later screen-state lines go in piece 6); core/edit.zig its `markRead`; the cell-for-cell dump the soak compares a client's terminal with its session's by moves to terminal.zig (`dumpScreen`, over the emulator), the soak's three streams (a shell's, a full-screen program's, `yes`) into test/replicas.zig, their one user; test/terminal.zig loses `a replica's terminal pane draws as its authority's does` (a delta's) and `a terminal made fresh has no size waiting` (`resize_to`'s); core-test 911/1068 (157 skipped), shell-test 1110/1113, term-test 15/15, pane-test 181/182 (again after the machines reboot, on a wiped cache), the soaks small run and `--echo` rc 0
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test/replicas.zig')
| -rw-r--r-- | test/replicas.zig | 62 |
1 files changed, 56 insertions, 6 deletions
diff --git a/test/replicas.zig b/test/replicas.zig index aa10d4a9..f4d8d450 100644 --- a/test/replicas.zig +++ b/test/replicas.zig @@ -39,7 +39,7 @@ const pardes = @import("pardes"); const replica = pardes.replica; const client_loop = @import("runtime").client; const session_loop = @import("runtime").session; -const screen_state = @import("term").screen_state; +const term = @import("term"); const Echo = pardes.Echo; const Key = pardes.Key; @@ -440,10 +440,10 @@ fn writeText(path: [:0]const u8, text: []const u8) !void { const Run = struct { seed: u64, rtt_ms: u64, steps: usize, clients: u16, flood_mb: u64 }; /// The terminal pane's screen as a hash of a dump of its cells. -fn screenHash(t: *screen_state.Terminal) u64 { +fn screenHash(t: anytype) u64 { var buf: [8192]u8 = undefined; var h: std.Io.Writer.Hashing(std.hash.Wyhash) = .initHasher(.init(0), &buf); - screen_state.dumpScreen(t, &h.writer) catch {}; + term.terminal.dumpScreen(t, &h.writer) catch {}; h.writer.flush() catch {}; return h.hasher.final(); } @@ -2125,9 +2125,9 @@ fn run(init: std.process.Init, r: Run, dir: []const u8, totals: *Totals) !void { // What the shell's program prints: a full-screen program, a shell's // session (prompts, titles, directories, a clear now and then), then a // flood of `yes` and of a `cat`, read 4 KB at a time as a pty gives it. - const tui = try screen_state.tuiStream(gpa); + const tui = try tuiStream(); defer gpa.free(tui); - const session_only = try screen_state.shellStream(gpa); + const session_only = try shellStream(); defer gpa.free(session_only); const shell_session = try std.mem.concat(gpa, u8, &.{ session_only, questions }); defer gpa.free(shell_session); @@ -2140,7 +2140,7 @@ fn run(init: std.process.Init, r: Run, dir: []const u8, totals: *Totals) !void { _ = shm.shm_unlink(object); } } - const yes_only = try screen_state.yesStream(gpa, @intCast(r.flood_mb * (1 << 20) / 3)); + const yes_only = try yesStream(@intCast(r.flood_mb * (1 << 20) / 3)); defer gpa.free(yes_only); const yes = try std.mem.concat(gpa, u8, &.{ yes_only, shown }); defer gpa.free(yes); @@ -2263,6 +2263,56 @@ fn images(dir: []const u8, seed: u64, media: *Media) ![]u8 { /// `before`, then `n` bytes of what a `cat` of source text prints through a /// pty: this file's lines, CR LF after each, again and again. +/// A shell's: prompts marked (OSC 133), colours of the three kinds, wide +/// and combined graphemes, hyperlinks, tabs, a title and a directory, long +/// lines that wrap, and a clear (ED2, ED3) now and then. +fn shellStream() ![]u8 { + var out: std.Io.Writer.Allocating = .init(gpa); + errdefer out.deinit(); + const w = &out.writer; + try w.writeAll("\x1b]0;a shell\x07\x1b]7;file://host/home/someone\x07"); + for (0..400) |i| { + try w.print("\x1b]133;A\x07$ \x1b]133;B\x07ls -l {d}\r\n\x1b]133;C\x07", .{i}); + try w.print("\x1b[1;31mred\x1b[0m \x1b[4;38;5;{d}m256\x1b[0m \x1b[38;2;{d};100;200;48;5;17mtrue\x1b[0m 漢字 e\u{301} 👩\u{200d}💻 ", .{ i % 256, i % 256 }); + try w.print("\x1b]8;;https://example.com/{d}\x07link\x1b]8;;\x07\tx\r\n", .{i}); + if (i % 7 == 0) { + for (0..12) |_| try w.writeAll("a long line that wraps "); + try w.writeAll("\r\n"); + } + try w.writeAll("\x1b]133;D;0\x07"); + if (i % 97 == 96) try w.writeAll("\x1b[H\x1b[2J\x1b[3J"); + if (i % 50 == 0) try w.print("\x1b]2;title {d}\x07\x1b]4;1;rgb:{x:0>2}/20/30\x07", .{ i, i % 256 }); + } + return out.toOwnedSlice(); +} + +/// A full-screen program's: the alternate screen and its modes, a status +/// line, a scrolling region scrolled both ways, lines inserted and +/// deleted, cursor shapes, the kitty keyboard pushed and popped. +fn tuiStream() ![]u8 { + var out: std.Io.Writer.Allocating = .init(gpa); + errdefer out.deinit(); + const w = &out.writer; + try w.writeAll("before the program\r\n\x1b[?1049h\x1b[?25l\x1b[?1000h\x1b[?1006h\x1b[?2004h\x1b[?1h\x1b[>1u\x1b[4 q\x1b[H\x1b[2J"); + for (0..300) |f| { + try w.print("\x1b[1;1H\x1b[44;97m status {d} \x1b[K\x1b[0m", .{f}); + try w.print("\x1b[3;18r\x1b[18;1H\r\n\x1b[3{d}mline {d}\x1b[0m", .{ f % 8, f }); + if (f % 3 == 0) try w.writeAll("\x1b[3;1H\x1bM\x1b[2mreversed in\x1b[0m"); + if (f % 5 == 0) try w.writeAll("\x1b[6;1H\x1b[2L\x1b[9;1H\x1b[M"); + try w.writeAll("\x1b[r"); + try w.print("\x1b[{d};{d}H\x1b[7m*\x1b[0m\x1b[{d}X", .{ 2 + f % 20, 1 + (f * 7) % 70, f % 5 }); + if (f % 11 == 0) try w.writeAll("\x1b[?25h\x1b[6 q") else if (f % 11 == 5) try w.writeAll("\x1b[?25l\x1b[2 q"); + } + try w.writeAll("\x1b[<u\x1b[?1049l\x1b[?25h\x1b[?1000l\x1b[0 qafter the program\r\n"); + return out.toOwnedSlice(); +} + +fn yesStream(lines: usize) ![]u8 { + const out = try gpa.alloc(u8, lines * 3); + for (0..lines) |i| @memcpy(out[i * 3 ..][0..3], "y\r\n"); + return out; +} + fn catAfter(before: []const u8, n: usize) ![]u8 { var out: std.ArrayListUnmanaged(u8) = .empty; errdefer out.deinit(gpa); |
