From 552400589c0514e8e3f9a9f96b23d2224302e1a7 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 14:38:59 -0300 Subject: tui: a terminal's resize says a terminal's row metrics (terminalSize: .row_metrics = .{}, one cell for its tag and its body), so a terminal client's view, opened from a window's (views.open gives a new view the live one's `sized` facts, row metrics among them, and a resize with none keeps them, Core.zig 1681), wraps its tags at its own width: the user's "in some of them contents got cut" (2026-11-24), the hunt's cause 4: a 100-column terminal client of a window's session wrapped the PDF's tag at 120 characters in a 98-cell row (the window's tagline glyphs a fifth narrower than its body: layout.tagCapacity), its first row cut and its second begun past what was cut, the middle of a long tag never shown (the hunt's screens: 124 characters, the second row " Del"); TEST FIRST: tui.zig "a terminal client's view, opened from a window's, wraps a tag at its own width" (two views, 140 and 100 columns, a file's pane with a 40-word tag): before, w22 to w27 missing; after, every word shown; the PDF's text cut at a narrower client's right edge is the PDF's text layer drawn line by line, unwrapped (pdf.zig paint), the same in a terminal session of that width alone; nothing on the wire changes shape (the field was there, null) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- dev/tui/tui.zig | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'dev/tui/tui.zig') diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index e2cdd2fa..91b25b7a 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -442,6 +442,11 @@ fn terminalSize(cols: u16, rows: u16, pixel_w: u16, pixel_h: u16) @FieldType(par .w = @intCast(terminalCellPixels(pixel_w, cols, 8)), .h = @intCast(terminalCellPixels(pixel_h, rows, 16)), }, + // A terminal's tag and body are one cell: its own row metrics, said, + // never those of the view its client's was opened from (a window's + // tagline is narrower than its body: a tag wrapped at a fifth more + // than its row held, the middle of a long tag never shown). + .row_metrics = .{}, }; } @@ -3289,3 +3294,46 @@ test "the tty draws a glide at whole rows: once a flick or a spin slows, its ste try std.testing.expectEqual(row, (shown.cursor orelse return error.NoCursor).y); } } +test "a terminal client's view, opened from a window's, wraps a tag at its own width: a terminal's resize says a terminal's row metrics" { + const gpa = std.testing.allocator; + const core = try pardes.Pardes.init(gpa, .{ .tty_only = true, .cols = 140, .rows = 45 }); + defer core.deinit(); + // The session's window: its tag line's glyphs narrower than its body's, + // so a tag row holds more of them than it has cells. + core.update(.{ .resize = .{ .cols = 140, .rows = 45, .cell_pixels = .{ .w = 16, .h = 33 }, .row_metrics = .{ .body_w = 16, .body_h = 33, .tagline_w = 13, .tagline_h = 26 } } }); + const pane = try core.setTestFile("text\n"); + var words: [40][3]u8 = undefined; + var tag: std.ArrayList(u8) = .empty; + defer tag.deinit(gpa); + for (&words, 0..) |*w, i| { + w.* = .{ 'w', '0' + @as(u8, @intCast(i / 10)), '0' + @as(u8, @intCast(i % 10)) }; + try tag.appendSlice(gpa, " "); + try tag.appendSlice(gpa, w); + } + if (pane.tag.own) |own| gpa.free(own); + pane.tag.own = try gpa.dupe(u8, tag.items); + // A terminal's client joins: its view opened from the window's, then + // sized by its terminal, as the client's first inputs do. + const k = core.openView().?; + core.toView(k); + core.update(.{ .resize = terminalSize(100, 30, 0, 0) }); + core.sync(); + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + const s = try core.render(arena.allocator()); + var shown: std.ArrayList(u8) = .empty; + defer shown.deinit(gpa); + for (s.regionList()) |region| { + if (region.kind != .tag) continue; + for (region.rect.y..region.rect.y + region.rect.h) |y| { + for (s.cells[y * s.cols ..][region.rect.x..][0..region.rect.w]) |cell| try shown.appendSlice(gpa, if (cell.len == 0) " " else cell.grapheme()); + try shown.append(gpa, '\n'); + } + } + // Each of its words shows: wrapped at its rows' width, none lost + // between a row cut short and the next. + for (&words) |*w| if (std.mem.indexOf(u8, shown.items, w) == null) { + std.debug.print("{s} is not shown in the tag:\n{s}\n", .{ w, shown.items }); + return error.TestUnexpectedResult; + }; +} -- cgit v1.3 From 4ae132650106242a5130aad5230c4f429bf02b29 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 14:43:18 -0300 Subject: replica, gui, tui: the clock a session's pump reads after its wait is held only while a client's post waits for it (Peers.heldNow, which both shells' clocks call), so a wait that ran out always reads the clock and its step meets the deadline it waited for: a window's session showing a PDF with a client attached stepped ~700 times a second with nobody typing, each step a unit every client replayed (the multi-client line's "a PDF in a window's session floods every client"); RUN (an instrumented Debug build, the window's loop offscreen with no test mode, a terminal client; .scratch reorg/pardes-idle-flood/runs/probe): the client's view of the PDF (pane 1, view 1: 78x9, 8x16, glyphs) owed to the kind from its join on (Kind.wake: now, so nextWake a frame on), and 2247 of 2268 pumps 'mail_only true, mail false, wait ran out', the clock read after each the one held at the join (1.302 s while the real one ran to 2.93 s), so advance never reached the deadline, the view was never told, and the next wait was 1 ms: for ever; THE CAUSE: dev/gui/gui.zig guiNow held the clock after any wait whose `mail_only` was still set, and waitInput sets it at a wait's start and clears it only for an event that is not a replica's wake or a queue message: a wait that ran out (SDL_WaitEventTimeout false, waitDetached's too) took no post and still held the clock; a terminal's session never did (its wait ends in a .wake event, tui.zig apply clears it); THE FIX: Peers.heldNow (core/replica.zig): held only when the wait took nothing else (the shell's `mail_only`), a client is attached (`recording`), a post waits to be taken (`mail`, set by post, cleared at the boundary) and the clock has started; gui.zig guiNow and tui.zig clockNow call it (their own copies of the rule gone), so no shell's wait can hold the clock without a post; TEST FIRST: test/panes.zig "a PDF shown and a client's view its kind was not told: the session's next pump, its wait run out with nobody typing, tells it, and nothing is owed after; a client's post waiting holds the clock" (on the base's rule, the same function without `mail`: fails at panes.zig:4120, the view still owed after the pump); test/daemon.py --client-idle on this build: the window's loop 7 boundaries and 8 units with a PDF against the text alone's 5 and 6 (4871 and 4872 on the base), the test surface 223 against 207 (388 against 206), the terminal's 8 against 5; a user hit it: every window's session with a client attached and a deadline owed (a PDF's view, a message's linger, a Life's tick, a look's hover) stepped and sent a unit a millisecond until someone typed in the window Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/replica.zig | 12 ++++++++ dev/gui/gui.zig | 7 ++--- dev/tui/tui.zig | 7 ++--- test/panes.zig | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 8 deletions(-) (limited to 'dev/tui/tui.zig') diff --git a/core/replica.zig b/core/replica.zig index 829972c2..875a7828 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -1911,6 +1911,18 @@ pub const Peers = struct { return n; } + /// The time the session's pump reads after its wait, when that wait + /// took a client's post and nothing else (`only_mail`, the shell's word + /// for its wait): the core's clock as it stands, so the pump's unit + /// moves nothing a client's speculation stands on; null otherwise (the + /// shell's clock). Held only while a post waits (`mail`): a wait that + /// ran out took none, and the pump after it is the one its deadline + /// asked for (a window's wait that ran out was held, 2026-11-24: a + /// deadline never met, the session stepped a millisecond for ever). + pub fn heldNow(ps: *const Peers, core: *const Pardes, only_mail: bool) ?u64 { + return if (only_mail and ps.recording and ps.mail.load(.acquire) and core.clock.started) core.clock.now_ns else null; + } + pub fn post(ps: *Peers, note: Note) void { ps.lock.lockUncancelable(ps.io); if (note == .join and ps.upgrading.load(.monotonic)) { diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index 9ea813fc..8fd8c24c 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -2457,9 +2457,8 @@ const Shell = struct { /// of their own with no window here; the session loop's /// (runtime/session.zig), a client's none. peers: *replica.Peers, - /// This wait took only a replica's post (its input, its join): the pump - /// after it reads no new time, so it moves nothing the replicas' - /// speculations stand on (tui.zig's `mail_only`). + /// This wait took nothing but a replica's post, if one (its input, its + /// join): the pump after one reads no new time (Peers.heldNow). mail_only: bool = false, waited: bool = false, /// With replica clients, a wait takes one person's input (tui.zig @@ -3167,7 +3166,7 @@ fn guiNow(ctx: ?*anyopaque) u64 { const s = shellOf(ctx); if (s.waited) { s.waited = false; - if (s.mail_only and s.peers.count() > 0 and s.core.clock.started) return s.core.clock.now_ns; + if (s.peers.heldNow(s.core, s.mail_only)) |held| return held; } return s.test_clock orelse s.paced_ns orelse c.SDL_GetTicksNS(); } diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index e2cdd2fa..312a0846 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -1240,9 +1240,8 @@ const Shell = struct { /// The session's replica clients (core/replica.zig), on sockets: the /// session loop's (runtime/session.zig); a client's, none. peers: *replica.Peers, - /// This wait took only a replica's post (its input, its join): the - /// pump after it reads no new time, so it moves nothing the replicas' - /// speculations stand on (a replica takes such a unit as is). + /// This wait took nothing but a replica's post, if one (its input, its + /// join): the pump after one reads no new time (Peers.heldNow). mail_only: bool = false, waited: bool = false, /// This wait's steps so far, and the input held for the next (`split`). @@ -1321,7 +1320,7 @@ const Shell = struct { const s = of(ctx); if (s.waited) { s.waited = false; - if (s.mail_only and s.peers.count() > 0 and s.core.clock.started) return s.core.clock.now_ns; + if (s.peers.heldNow(s.core, s.mail_only)) |held| return held; } return s.test_clock orelse @intCast(std.Io.Clock.awake.now(s.io).nanoseconds); } diff --git a/test/panes.zig b/test/panes.zig index bd39beba..28a3b256 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -4047,6 +4047,90 @@ const PdfAddon = struct { } } + /// A session's loop with nobody typing: each wait runs out at its + /// deadline, and the clock read after it is the shells' (Peers.heldNow, + /// as gui.zig `guiNow` and tui.zig `clockNow` read it: a wait that took + /// nothing else, `only_mail`). + const Idle = struct { + now: u64 = std.time.ns_per_s, + waited: bool = false, + core: ?*Pardes = null, + peers: pardes.replica.Peers = .{ .gpa = std.testing.allocator, .io = std.testing.io }, + + const vtable: pardes.Host.VTable = .{ + .wait_input = wait, + .now = clock, + .watched = host_vtable.watched, + .job = host_vtable.job, + }; + + fn wait(ctx: ?*anyopaque, timeout_ms: u32) void { + const h: *Idle = @ptrCast(@alignCast(ctx.?)); + h.now += @as(u64, timeout_ms) * std.time.ns_per_ms; + h.waited = true; + } + + fn clock(ctx: ?*anyopaque) u64 { + const h: *Idle = @ptrCast(@alignCast(ctx.?)); + if (!h.waited) return h.now; + h.waited = false; + return h.peers.heldNow(h.core orelse return h.now, true) orelse h.now; + } + }; + + test "a PDF shown and a client's view its kind was not told: the session's next pump, its wait run out with nobody typing, tells it, and nothing is owed after; a client's post waiting holds the clock" { + // 2026-11-24: a window's session showing a PDF, a client attached, + // stepped ~700 times a second with nobody typing: the client's view + // owed to the kind (Kind.wake: now), a wait of a millisecond that + // ran out, and the clock after it held as if a client had posted + // (gui.zig guiNow: its wait's `mail_only` is cleared by an event, + // and one that ran out had none), so no step met the deadline. + if (!addons.has_pdf) return error.SkipZigTest; + const R = pardes.replica; + var idle: Idle = .{}; + defer idle.peers.deinit(); + const a = try R.Authority.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, .{ .ctx = &idle, .vtable = &Idle.vtable }); + defer a.deinit(); + idle.core = a.core; + const Land = struct { + a: *R.Authority, + fn step(l: @This(), ev: pardes.Event) !void { + _ = try l.a.local(ev); + } + }; + const id = try opened(a, Land{ .a = a }); + const slot = a.core.panes[id].?.addon.?; + // A client attached (units go to it), its view sized by its input: + // a client's step tells no kind (17.2), so its view is owed. + idle.peers.recording = true; + const k = (try a.openView(2)).view; + const was = pardes.tape.on; + pardes.tape.on = &a.t; + const bytes = try pardes.dump.byteDump(a.core); + pardes.tape.resync(&a.t); + pardes.tape.on = was; + defer a.core.gpa.free(bytes); + const win = try R.Replica.initDump(std.testing.allocator, 2, k, bytes, .{ .cols = 80, .rows = 24 }); + defer win.deinit(); + _ = try a.take(try win.input(.{ .resize = .{ .cols = 80, .rows = 24 } })); + try std.testing.expect(pardes.Kind.viewOwed(a.core, slot, id)); + // ONE pump, nobody typing: its wait runs out at the wake, the step + // it asked for tells the view, and nothing is owed after. + a.pump(); + try std.testing.expect(!pardes.Kind.viewOwed(a.core, slot, id)); + try std.testing.expect((pardes.Kind.wake(a.core) orelse std.math.maxInt(u64)) > a.core.clock.now_ns); + // A client's post waiting (its input, its join): the pump before + // the boundary takes it reads the clock as it stands. + const at = a.core.clock.now_ns; + idle.now += std.time.ns_per_s; + idle.peers.mail.store(true, .release); + a.pump(); + try std.testing.expectEqual(at, a.core.clock.now_ns); + idle.peers.mail.store(false, .release); + a.pump(); + try std.testing.expectEqual(idle.now, a.core.clock.now_ns); + } + test "a PDF pane whose file changes on disk opens again from it at its page, its fit kept" { if (!addons.has_pdf) return error.SkipZigTest; const gpa = std.testing.allocator; -- cgit v1.3