From b1fb4242c0ab52767df1b8e155edcf2692f37873 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 23 Nov 2026 18:00:35 -0300 Subject: scroll: a view's top is a line and a row within that line's own wrapped rows, and a scroll moves it by rows (P62, round 3, on the layer's new model where the `Changes` layer's lines are lines of the buffer): a wheel's notch, the glide, PageDown/PageUp, zj/zk, Ctrl-d/u, zt/zz/zb and the margin (`scroll_off` now ROWS) go a row at a time through a line wrapped over many rows and through a long description line of the layer, where the base jumped all of a wrapped line's rows at once (the user, 2026-11-23: "the scroll view jumps around near deleted lines on the diff view"; one-row deleted lines were cured by the layer's second step, a wrapped one was not): TESTS FIRST: core/jj.zig "a view scrolls by rows through a line wrapped over 12 rows and a change's description wrapped over several (a line of the layer): ..." (a notch is one row down the whole text and back, the notches the text's rows exactly; PageDown/PageUp a page of rows; zj/zk one; a held j and k keep the cursor's row `scroll_off` rows inside the body) failing on the base at notch 21 (line 20's 12 rows crossed at once), and "a client wheels its session's view a row a notch into a change's description wrapped over several rows ..., agreeing at every notch; a client joined over that view loads its row"; kept from round 1: core/replica.zig's join over a view scrolled into a wrapped line (with a rollback and a dump) and the explorer of a view's rows (30 seeds), dev/gui's glide a row a notch; THE CHANGE, taken from pardes-row-scroll (`xrxmqlnw`) and -2 (`xxzmwnvq`) without their ghost-row "blocks" (a block is now just a line's own rows): `File.State.scroll_row` and `views.PaneView.scroll_row` in the generic walk (digested, dumped, copied; a dump of 34 loads at its lines' first rows), the wire 35; core/File.zig `Top`, `rowIn`/`rowWalked` (a line's rows as fillBody wraps them, `guideOf` shared), `rowOf`, `lineRows`, `top`/`setTop`, `walkRows`/`walkKnown`, `rowsTo`, `rowsOf` (off the map where it holds the line), `mapFresh`, `scrollRows`, `shownRows` (the geometry laid out first), `show` (a cursor's or a result's row inside the band, the line's rows whole when they fit), `textRowLine`, fillBody's skip to the top's row walked once a geometry (`Pane.top_skip`, derived), the geometry's key with `scroll_row` and stored as what the map was made from; the one-row fact `State.widest` (`Widest`, an upper bound kept by the index's own vector passes `countLines`/`fillLines`) so a view whose lines are each one row walks nothing (`oneRow`: line arithmetic, checked against the walk in Debug); `fitEnd` a vector of printable ASCII at a time; the callers in rows: panes.zig `scrollBy(tab, delta)` and `ensureCursorVisible` (a file's through `File.show`), the wheel and the rail and the edge scroll (mouse.zig), Ctrl-d/u (normal.zig `halfPageMove`), zt/zz/zb, Ctrl-f/b and PgUp/PgDn (Text.zig `scrollViewMove`), Look's reveal and centring, Places' `goTo`/`restore`, Query's `showCurrent`/`caretTo`, the frames' `Region.row` and the glide (dev/glide.zig, the window's `topOf`); test/perf.zig's checks by (line, row) and its seek at a line's first row; Debug in the workspace: core-test 963/1129 (166 skipped), shell-test 1172/1175 (3 skipped) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- dev/glide.zig | 43 ++++++++++++++++++++++++----------------- dev/gui/gui.zig | 60 ++++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 67 insertions(+), 36 deletions(-) (limited to 'dev') diff --git a/dev/glide.zig b/dev/glide.zig index 62e44bb7..9d622b3d 100644 --- a/dev/glide.zig +++ b/dev/glide.zig @@ -2,8 +2,9 @@ //! scroll, on its own clock, from the frames it draws alone. Whatever //! scrolls a text (a wheel's lines, Ctrl-d, a page, G, n, a Look) scrolls //! the core at once, so every key and click acts on where the text is; the -//! frontend sees a body's first line move between two frames (Region.line) -//! and its picture follows there, critically damped (text never passes its +//! frontend sees a body's top move between two frames (Region.line, and +//! Region.row: a row inside a wrapped line, File.Top) and its picture +//! follows there, critically damped (text never passes its //! mark), every distance on the same law. The GUI draws it at the pixel; //! the tty at whole rows (tui.zig's glideRows). Nothing here reaches back //! into the core. @@ -60,9 +61,9 @@ pub const Glide = struct { caret_row: ?u16 = null, caret_rides: bool = false, /// Each body as the last frame showed it, by its pane: its serial, - /// first line, text and place, so a view that moved since is found - /// whatever moved it. - seen: [pardes.MAX_PANES]struct { serial: u32 = 0, line: i32 = 0, doc: u64 = 0, rect: pardes.Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 } } = @splat(.{}), + /// top (a line and a row of it), text and place, so a view that + /// moved since is found whatever moved it. + seen: [pardes.MAX_PANES]struct { serial: u32 = 0, line: i32 = 0, row: u32 = 0, doc: u64 = 0, rect: pardes.Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 } } = @splat(.{}), /// Each body's rows held at its top while it scrolls (a source's /// sticky context rows, TreeContext), its frontend's to say: they do /// not move, so a move is measured, and the rows that left are kept, @@ -121,7 +122,9 @@ pub const Glide = struct { /// The frame about to be drawn, at `now_ns` on the frontend's clock: /// the glide moves on to now, and a body whose first line moved since /// the last frame (the same text in the same place) is measured against - /// that frame and kicks it. A terminal's view glides only under the + /// that frame and kicks it: a move of lines guessed at as many rows (as + /// unwrapped), one inside a line's wrapped rows known in rows. A + /// terminal's view glides only under the /// wheel (`wheeled`: its output scrolls it at every line, and that is no /// glide); not one the frontend moves by the pixel (`direct`). One glide /// at a time: the focused body's, else the one that moved most. @@ -139,24 +142,26 @@ pub const Glide = struct { } var pick: ?pardes.Region = null; var delta: i64 = 0; + var lines: i64 = 0; var shown: [pardes.MAX_PANES]bool = @splat(false); for (surface.regionList()) |region| { if (region.kind != .body or region.owner >= glide.seen.len) continue; const id: usize = region.owner; shown[id] = true; const was = glide.seen[id]; - glide.seen[id] = .{ .serial = region.serial, .line = region.line, .doc = region.doc, .rect = region.rect }; - if (was.serial != region.serial or was.doc != region.doc or was.line == region.line) continue; + glide.seen[id] = .{ .serial = region.serial, .line = region.line, .row = region.row, .doc = region.doc, .rect = region.rect }; + if (was.serial != region.serial or was.doc != region.doc or (was.line == region.line and was.row == region.row)) continue; // The last frame drew this body where it is now: a pane that // moved or was resized in the same step has no picture to glide // from. if (!std.meta.eql(was.rect, region.rect)) continue; if (region.doc == 0 and wheeled != id) continue; if (direct == id) continue; - const moved = @as(i64, region.line) - was.line; + const moved = if (region.line != was.line) @as(i64, region.line) - was.line else @as(i64, region.row) - was.row; if (pick) |best| if (best.active or (!region.active and @abs(moved) <= @abs(delta))) continue; pick = region; delta = moved; + lines = @as(i64, region.line) - was.line; } for (&glide.seen, shown) |*seen, here| if (!here) { seen.* = .{}; @@ -179,8 +184,8 @@ pub const Glide = struct { if (glide.before.len < n) return glide.stop(); for (0..r.h) |row| @memcpy(glide.before[row * w ..][0..w], glide.last[(@as(usize, r.y) + row) * glide.last_cols + r.x ..][0..w]); glide.dir = @intCast(std.math.sign(delta)); - glide.pending_lines += @floatFromInt(@abs(delta)); - glide.measure(gpa, surface); + glide.pending_lines += @floatFromInt(@abs(lines)); + glide.measure(gpa, surface, @floatFromInt(@abs(delta))); } /// This frame's cells and caret, for the next frame's measure. @@ -202,8 +207,9 @@ pub const Glide = struct { } /// Finds how far the pane's body rows moved, `dir` rows at a time, by - /// the rows of `surface` against `before`; keeps the rows that left. - fn measure(glide: *Glide, gpa: std.mem.Allocator, surface: *const pardes.Surface) void { + /// the rows of `surface` against `before` (`guess` rows tried first); + /// keeps the rows that left. + fn measure(glide: *Glide, gpa: std.mem.Allocator, surface: *const pardes.Surface, guess_rows: f32) void { const w = glide.bw(); const x0 = glide.rect.x + config.GUTTER; if (w == 0 or glide.body_h == 0 or x0 + w > surface.cols or glide.body_y + glide.body_h > surface.rows or glide.before.len < @as(usize, w) * glide.body_h) return glide.stop(); @@ -218,9 +224,10 @@ pub const Glide = struct { }; // The least shift under which the rows agree, but for a few: the // cursor's line and its number's weight move with the scroll. The - // lines the core moved are tried first: unwrapped, they are the - // rows, and one pass over the body settles it (the search over - // every shift was 6 ms of the first frame of a page in Debug). + // rows guessed are tried first: the lines the core moved, which are + // the rows unwrapped, or the rows inside a wrapped line; one pass over the + // body settles it (the search over every shift was 6 ms of the + // first frame of a page in Debug). const agrees = struct { fn at(gl: *const Glide, surf: *const pardes.Surface, x: u16, width: u16, height: u16, kk: u16) bool { if (kk == 0 or kk + 3 > height) return false; @@ -239,7 +246,7 @@ pub const Glide = struct { return true; } }; - const guess: u16 = @intFromFloat(@min(glide.pending_lines, @as(f32, @floatFromInt(h)))); + const guess: u16 = @intFromFloat(@min(guess_rows, @as(f32, @floatFromInt(h)))); // A body's lines or more: every row moved off, none in common. var shift: u16 = if (guess >= h) 0 else if (agrees.at(glide, surface, x0, w, h, guess)) guess else found: for (1..h) |k| { if (agrees.at(glide, surface, x0, w, h, @intCast(k))) break :found @intCast(k); @@ -252,7 +259,7 @@ pub const Glide = struct { // None in common: a body's move from the last frame's body, if the // lines moved are that many (rows that merely changed, a small // scroll the rows cannot show, land at once). - if (shift == 0 and glide.pending_lines + 3 < @as(f32, @floatFromInt(h))) return glide.stop(); + if (shift == 0 and guess_rows + 3 < @as(f32, @floatFromInt(h))) return glide.stop(); const far = shift == 0; if (far) shift = h; glide.caret_rides = !far and if (glide.caret_row) |old| if (surface.cursor) |c| diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index 2756f69b..0f1fe0e6 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -1773,10 +1773,9 @@ const Input = struct { /// Pane `id`'s first row shown, after the inputs posted: the session's /// own window asks (a wheel's rows stop where the pane does); a replica /// client's speculation may wait on the session, so it never asks. - fn scrollOf(in: *const Input, id: usize) ?i32 { + fn scrollOf(in: *const Input, id: usize) ?[2]i64 { if (in.client != null) return null; - const pane = in.core.panes[id] orelse return null; - return pane.scroll(); + return topOf(in.core.panes[id] orelse return null); } fn close(in: *Input) void { @@ -3301,6 +3300,12 @@ fn notchOf(raw_y: f32, integer_y: i32) ?i32 { const Glide = pardes.glide.Glide; +/// Where a pane's view starts, to tell a wheel's row moved it: its line, +/// and a file's row of that line's wrapped rows (File.Top). +fn topOf(pane: *pardes.Pane) [2]i64 { + return .{ pane.scroll(), if (pane.file) |f| f.scroll_row else 0 }; +} + /// Feeds a wheel's notches to the core, and keeps what moved the view for /// the frame's glide (Glide.frame). fn stepGlide(g: *Gui, core: *pardes.Pardes) void { @@ -3322,10 +3327,10 @@ fn stepGlide(g: *Gui, core: *pardes.Pardes) void { while (left != 0) { const down = left > 0; left += if (down) -1 else 1; - const was = pane.scroll(); + const was = topOf(pane); // Shift: pardes's own scroll, never a program's wheel. core.update(.{ .mouse = .{ .button = if (down) .wheel_down else .wheel_up, .kind = .press, .col = g.scroll_col, .row = g.scroll_row, .shift = true } }); - if (pane.scroll() == was) break; + if (std.mem.eql(i64, &topOf(pane), &was)) break; wheeled = id; } if (wheeled != null) core.needs_frame = true; @@ -3541,7 +3546,7 @@ fn scrollRows(g: *Gui, in: *Input, gpa: std.mem.Allocator) bool { }, }); // A replica client's rows may wait on the session: it never asks. - if (was != null and in.scrollOf(id) == was) { + if (was != null and std.mem.eql(i64, &in.scrollOf(id).?, &was.?)) { resetScroll(g); return false; } @@ -6544,16 +6549,19 @@ test "a wheel over codex in a terminal reaches its pty as the mouse reports it a try std.testing.expectEqual(@as(i32, -1), g.scroll_notch); } -test "a notch scrolls the core at once and the picture glides after it, a wrapped line's rows at a time" { +test "a notch scrolls the core at once and the picture glides after it, a row a notch: a wrapped line's rows one by one" { const gpa = std.testing.allocator; const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 }); defer core.deinit(); - // Lines of two rows each at this width, numbered so no two rows match. + // Lines of two rows each at this width, numbered so no two rows match; + // line 3 of 80 numbered words, five rows or more. var text: std.ArrayList(u8) = .empty; defer text.deinit(gpa); for (0..60) |i| { try text.print(gpa, "{d:0>4} ", .{i}); - try text.appendNTimes(gpa, 'a' + @as(u8, @intCast(i % 26)), 100); + if (i == 3) { + for (0..80) |w| try text.print(gpa, "w{d:0>3} ", .{w}); + } else try text.appendNTimes(gpa, 'a' + @as(u8, @intCast(i % 26)), 100); try text.append(gpa, '\n'); } _ = try core.setTestFile(text.items); @@ -6570,26 +6578,42 @@ test "a notch scrolls the core at once and the picture glides after it, a wrappe g.scroll_col = r.x + 10; g.scroll_row = r.y + r.h - 2; const body_y = core.bodyTop(core.panes[core.view().active].?, r); - const row_before = try gpa.dupe(pardes.Cell, s.cells[@as(usize, body_y + 1) * s.cols + r.x + config.GUTTER ..][0 .. r.w - config.GUTTER]); + const row_before = try gpa.dupe(pardes.Cell, s.cells[@as(usize, body_y) * s.cols + r.x + config.GUTTER ..][0 .. r.w - config.GUTTER]); defer gpa.free(row_before); // The window has drawn the view once (Glide.frame finds a view that moved). g.now_ns = now; glideFrame(&g, gpa, s); - // One notch down: the core is a line on at once. + // One notch down: the core is a row on at once, line 0's second. g.scroll_notch = 1; - const scrolled = core.panes[core.view().active].?.scroll(); + const f = &core.panes[core.view().active].?.file.?; stepGlide(&g, core); - try std.testing.expectEqual(scrolled + 1, core.panes[core.view().active].?.scroll()); + try std.testing.expectEqual(@as(usize, 0), f.scroll); + try std.testing.expectEqual(@as(u32, 1), f.scroll_row); _ = arena.reset(.retain_capacity); s = try core.render(arena.allocator()); glideFrame(&g, gpa, s); // The window's own motion: it draws its frames while it moves. try std.testing.expect(frontendMoving(&g)); - // Its two rows: the picture two rows behind, the rows that left kept, - // nearest first. - try std.testing.expectApproxEqAbs(@as(f32, -2), g.glide.follow.offset, 1e-4); - try std.testing.expectEqual(@as(u16, 2), g.glide.nabove); + // Its row: the picture a row behind, the row that left kept. + try std.testing.expectApproxEqAbs(@as(f32, -1), g.glide.follow.offset, 1e-4); + try std.testing.expectEqual(@as(u16, 1), g.glide.nabove); try std.testing.expect(pardes.glide.sameRow(g.glide.above[0 .. r.w - config.GUTTER], row_before)); + // Notch by notch to line 5, through line 3's rows: a row more + // behind each, never a line's rows at once. + var lag = g.glide.follow.offset; + var notches: usize = 1; + while (f.scroll < 5) : (notches += 1) { + g.scroll_notch = 1; + stepGlide(&g, core); + _ = arena.reset(.retain_capacity); + s = try core.render(arena.allocator()); + glideFrame(&g, gpa, s); + try std.testing.expectApproxEqAbs(lag - 1, g.glide.follow.offset, 1e-4); + lag = g.glide.follow.offset; + } + const line3: usize = pardes.panes.File.lineRows(core.settings.tab, core.panes[core.view().active].?, 3); + try std.testing.expect(line3 >= 5); + try std.testing.expectEqual(2 + 2 + 2 + line3 + 2, notches); // Frame by frame it comes back, never past, and settles. var frames: usize = 0; while (g.glide.moving()) : (frames += 1) { @@ -7746,7 +7770,7 @@ test "a body tells its first line" { const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 }); defer core.deinit(); const pane = try core.setTestFile(std.mem.asBytes(&@as([80][5]u8, @splat("line\n".*)))); - pane.scrollBy(8); + pane.scrollBy(core.settings.tab, 8); core.sync(); const s = try core.render(core.scratch.allocator()); const body = for (s.regionList()) |region| { -- cgit v1.3 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') 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') 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 From f0b23904f81d261b4f80544bf3c5cc7aafbf440b Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 15:20:26 -0300 Subject: gui: imageScissor is the placement's cells again: item 3's change (nvuylkxw, installed as 654a1632400a) kept a throwaway line of its own experiment (every picture's clip widened by 100000 px, to make SDL's scissor assertion fire on the test surface), restored in the wrong tree (a copy from inside the sketchbook checkout, whose ../pardes is ws-gate's): held to the target by sketchbook's Cells.onTarget it asserted nothing, but a picture was no longer cut at its pane's right edge (a PDF page or an image wider than its pane drew over the panes to its right); no gate row has a picture past its pane's right edge (77/77 frames identical with it); TEST FIRST: gui.zig "a picture's scissor is its placement's cells, cut at its pane's edges" (expected 40, found 100040 on the installed line; passes now) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- dev/gui/gui.zig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'dev') diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index 9ea813fc..aba74a94 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -3904,7 +3904,7 @@ fn imageScissor(g: *const Gui, place: pardes.Placement) c.SDL_Rect { return .{ .x = @intCast(@as(u32, place.dst.x) * g.cell_w), .y = @intCast(@as(u32, place.dst.y) * g.cell_h), - .w = @intCast(@as(u32, place.dst.w) * g.cell_w + 100000), // THROWAWAY: past any target + .w = @intCast(@as(u32, place.dst.w) * g.cell_w), .h = @intCast(@as(u32, place.dst.h) * g.cell_h), }; } @@ -7010,6 +7010,13 @@ test "a held key moves the view at the stream's own rate, never a bounce a line, for (70..90) |k| try std.testing.expectEqual(held.carets[70], held.carets[k]); } +test "a picture's scissor is its placement's cells, cut at its pane's edges" { + const g = testGui(10, 20, 6, 12); + var place: pardes.Placement = undefined; + place.dst = .{ .x = 2, .y = 3, .w = 4, .h = 5 }; + try std.testing.expectEqual(c.SDL_Rect{ .x = 20, .y = 60, .w = 40, .h = 100 }, imageScissor(&g, place)); +} + test "a scroll's shifted rows start under the context rows, and its scissor below their band" { var surface: pardes.Surface = .{}; var g = testGui(10, 20, 6, 12); -- cgit v1.3