summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/term/terminal.zig31
-rw-r--r--test/replicas.zig20
2 files changed, 39 insertions, 12 deletions
diff --git a/core/term/terminal.zig b/core/term/terminal.zig
index 055c8981..2f9f7b33 100644
--- a/core/term/terminal.zig
+++ b/core/term/terminal.zig
@@ -1801,3 +1801,34 @@ test "a join at a cut: every side reloaded from its own snapshot holds the same
// another terminal once heavy colour has pruned pages cut otherwise.
try std.testing.expectEqual(2, heavy_apart);
}
+
+test "wide characters filling a scrollback past its limit, reflowed: its snapshot loads to the same snapshot and hash, and goes on as the same terminal through more bytes and reflows" {
+ // The soak's `cat` (test/replicas.zig): source lines, one in a few
+ // hundred with wide characters (CJK, box drawing, ambiguous symbols),
+ // a full scrollback pruned a page at a time, reflowed at odd widths
+ // where a wide character meets the right edge.
+ const gpa = std.testing.allocator;
+ var out: std.Io.Writer.Allocating = .init(gpa);
+ defer out.deinit();
+ const wide = " try writeText(notes, \"# Fallback faces and rules\\n\\n| name | glyphs |\\n|------|--------|\\n| cjk | \u{754C}\u{9762}\u{5B57} |\\n| sym | \u{222E} \u{2260} \u{2605} |\\n\\n\u{250C}\u{2500}\u{2500}\u{252C}\u{2500}\u{2500}\u{2510}\\n\u{2502} a\u{2502} b\u{2502}\\n\u{2514}\u{2500}\u{2500}\u{2534}\u{2500}\u{2500}\u{2518}\\n\");";
+ for (0..30000) |i| {
+ if (i % 7 == 3) try out.writer.print("{s}\r\n", .{wide}) else try out.writer.print("{s} {d}\r\n", .{ " const line = std.fmt.bufPrint(&buf, \"{d}\", .{i}) catch continue;"[0 .. 8 + i % 60], i });
+ }
+ const bytes = out.written();
+ const stops: [2]usize = .{ bytes.len / 3, 2 * bytes.len / 3 };
+ const first = try openKeeping(gpa, 121, 40, 1 << 20);
+ defer close(first);
+ feedReflowing(first, bytes, 0, bytes.len / 2, stops);
+ const snap = try snapshotOf(gpa, first);
+ defer gpa.free(snap);
+ const loaded = try load(gpa, snap, &parts(first));
+ defer close(loaded);
+ const again = try snapshotOf(gpa, loaded);
+ defer gpa.free(again);
+ try std.testing.expectEqualSlices(u8, snap, again);
+ try std.testing.expectEqual(joinHash(snap), try reload(first));
+ try expectSame(gpa, first, loaded);
+ feedReflowing(first, bytes, bytes.len / 2, bytes.len, stops);
+ feedReflowing(loaded, bytes, bytes.len / 2, bytes.len, stops);
+ try expectSame(gpa, first, loaded);
+}
diff --git a/test/replicas.zig b/test/replicas.zig
index 5cddf6c8..e0e8b601 100644
--- a/test/replicas.zig
+++ b/test/replicas.zig
@@ -330,7 +330,7 @@ const Totals = struct {
/// search (`/`, a pattern, Enter), a sweep of B1 over the PDF and its
/// wheel; a yank to the system clipboard and a paste from it; now and
/// then a client's Detach.
-fn nextEvent(random: std.Random, buf: *[64]u8, aim: Aim, looks: []const []const u8, script: *Script) pardes.Event {
+fn nextEvent(random: std.Random, buf: *[64]u8, aim: Aim, looks: []const []const u8, script: *Script, far: bool) pardes.Event {
const typed = "abcdefghijklmnopqrstuvwxyz0123456789 -_=+,:;()";
const normal = "hjklwbe0$xpuyoOiaAIdcv.nN%sC";
if (script.at < script.n) {
@@ -374,8 +374,9 @@ fn nextEvent(random: std.Random, buf: *[64]u8, aim: Aim, looks: []const []const
10 => "Tab 8",
11 => "Life",
// Its link ended by the session (the session's own view's,
- // its terminal's: none here).
- 12 => if (random.uintLessThan(u8, 4) == 0) "Detach" else "Undo",
+ // its terminal's: none here). Not the far client's: the scene
+ // waits for its screen after the flood.
+ 12 => if (random.uintLessThan(u8, 4) == 0 and !far) "Detach" else "Undo",
// The system clipboard, the client's own frontend's (client.zig
// `asks`): a yank of the selection to it, a paste from it.
13 => "ClipYank",
@@ -1504,7 +1505,7 @@ const Soak = struct {
switch (m.kind) {
.input => {
var buf: [64]u8 = undefined;
- const ev = nextEvent(s.random, &buf, s.aim, s.looks, &cl.script);
+ const ev = nextEvent(s.random, &buf, s.aim, s.looks, &cl.script, net.throttled == @as(?usize, c));
cl.loop.input(ev);
cl.left -= 1;
if (cl.left > 0) try net.send(.{ .at = m.at + typistGap(s.random), .n = 0, .kind = .input, .who = m.who, .bytes = &.{} }) else {
@@ -1576,7 +1577,7 @@ const Soak = struct {
const core = s.l.core;
s.clock();
var buf: [64]u8 = undefined;
- const ev = nextEvent(s.random, &buf, s.aim, s.looks, &s.own_script);
+ const ev = nextEvent(s.random, &buf, s.aim, s.looks, &s.own_script, false);
core.toView(.at(0));
core.update(ev);
s.own_left -= 1;
@@ -1653,6 +1654,7 @@ const Soak = struct {
const want = pardes.tape.digestOf(core);
totals.cut += s.l.peers.cut;
if (bytes_kind) std.debug.print("seed {d} rtt {d} ms: a join's step at worst {d} us (the session's reloads and its dump), the last dump {d} KB ({d} KB of state)\n", .{ s.r.seed, s.r.rtt_ms, s.join_worst / 1000, s.l.peers.dump_bytes >> 10, s.l.peers.state_bytes >> 10 });
+ if (s.net.throttled) |c| if (!s.far_final) std.debug.print("seed {d} rtt {d} ms: the far client never showed the screen after the flood ({s})\n", .{ s.r.seed, s.r.rtt_ms, if (s.clients[c].r == null) "it left" else "it is joined" });
if (bytes_kind and s.kitty_answers != 1) {
totals.unequal += 1;
std.debug.print("seed {d} rtt {d} ms: the program's kitty query was answered {d} times on the session's pty\n", .{ s.r.seed, s.r.rtt_ms, s.kitty_answers });
@@ -1824,13 +1826,7 @@ fn catAfter(before: []const u8, n: usize) ![]u8 {
try out.appendSlice(gpa, before);
while (out.items.len < before.len + n) {
var lines = std.mem.splitScalar(u8, @embedFile("replicas.zig"), '\n');
- // Its lines of ASCII: one with a wide character, the scrollback
- // reloaded at joins between reflows, still parts a client from the
- // session (reports/pardes-term-lag.md), a fault of its own.
- next: while (lines.next()) |line| {
- for (line) |ch| if (ch >= 0x80) continue :next;
- try out.print(gpa, "{s}\r\n", .{line});
- }
+ while (lines.next()) |line| try out.print(gpa, "{s}\r\n", .{line});
}
out.shrinkRetainingCapacity(before.len + n);
return out.toOwnedSlice(gpa);