summaryrefslogtreecommitdiff
path: root/src/tui/tui.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-05 13:56:13 -0300
committerGabriel Schneider <[email protected]>2026-11-05 15:26:36 -0300
commit3488111273764c17a42870484fabc36abb0634a1 (patch)
treefa5440938b0feb1b0b38c3bca92326501a622413 /src/tui/tui.zig
parentc2885d899c95b9c4a72786940289afd0b3ddbde8 (diff)
downloadpardes-3488111273764c17a42870484fabc36abb0634a1.tar.gz
pardes-3488111273764c17a42870484fabc36abb0634a1.zip
effects out, the core's motion: the view's glide is the frontends' alone, and the core keeps no motion and no clock but its deadlines; glide.zig is a frontend's picture of a scroll, measured on the frame it is about to draw against the last it drew (a body's first line and the text it shows in its region, Region.doc new; the last frame's cells kept by the glide itself), on the frontend's own clock, the tty drawing it at whole rows and the window at the pixel; each frontend draws its own motions' frames from the last frame (the tty's poll presents it again, the window's loop renders it again, as its blink did) and paces its own waits, so the core's continuous path goes (Pardes.continuous and shell_continuous, the pump's one-millisecond wait, the view's drawn fields, the tape's watch of it); the Motion word and its five flavours go (the glide and the caret move at the default's pace, and no switch for reduced motion is left), and animation.zig with them (Motion and Spring gone, Follow now glide.zig's with its test, CursorGlide gone with the core's caret, Blink the window's with its test, Box and layout.panelBox gone, the frame's length now Pardes.frame_ns); a PDF strip no longer glides, its scroll landing at once (its follow, stripAt's motion and Pdf.moving go); the window's glide tests are fed frame by frame as the window feeds them; the window monkey runs by seed, not by flavour, and the 9P monkey loses Motion; the tty wakes a frame at a time while its glide or trail moves, as the core's continuous path woke it; all 109 snapshot goldens and the 16 GUI goldens unchanged; tests gone: a carried spring keeps its speed; a spring settles without overshoot; each flavour is its own motion; a cursor eases a cell at a time (animation.zig's); a PDF strip glides a notch and a page to their marks; a PDF glide renders the pages it crosses
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/tui/tui.zig')
-rw-r--r--src/tui/tui.zig67
1 files changed, 36 insertions, 31 deletions
diff --git a/src/tui/tui.zig b/src/tui/tui.zig
index 319e6c1b..05d29272 100644
--- a/src/tui/tui.zig
+++ b/src/tui/tui.zig
@@ -1335,7 +1335,7 @@ pub fn remote(init: std.process.Init, opts: pardes.Options, path: []const u8, se
}
if (link.owed or r.echo.changed) link.dirty = true;
// Predictions out: judged a frame at a time while they are.
- if (r.echo.n > 0 or r.echo.cursor != null or r.echo.nd > 0) requestWake(io, @intCast(pardes.animation.frame_ns / std.time.ns_per_ms));
+ if (r.echo.n > 0 or r.echo.cursor != null or r.echo.nd > 0) requestWake(io, @intCast(pardes.frame_ns / std.time.ns_per_ms));
if (link.quietCheck()) |ms| requestWake(io, ms);
if (r.diverged != null) link.quit = true;
}
@@ -1910,7 +1910,7 @@ const Shell = struct {
.now = clockNow,
.present = present,
.post_present = postPresent,
- .poll_frame = stepGlide,
+ .poll_frame = ownFrame,
};
const vtable: host_io.Host.VTable = .{
@@ -2215,12 +2215,16 @@ const Shell = struct {
const s = of(ctx);
// The wait is the 9P connections' turn with the core. A timeout (the
// core's next wake) arrives through the same queue (`wakeWatch`).
- // While anything moves, a frame a tick (animation.frame_ns) on a grid
+ // While anything moves, a frame a tick (pardes.frame_ns) on a grid
// of them, as the GUI paces to its display: the loop ran as fast as
// the terminal answered, a frame every 2 ms, each a write. An input
// ends the wait at once and its frame is drawn then; the ticks after
// it run from it.
var wait = timeout_ms;
+ // The tty's own motions (its glide, a jump's trail) wake it a frame at
+ // a time while they move: on a virtual clock a millisecond's wait
+ // moves it a frame (waitOnce), on the real one the pace below sets it.
+ if (s.moving()) wait = 1;
// Detached, nobody's key dismisses a message: they go on the clock
// (the pump's, after this wait), which wakes it.
if (!s.attached()) {
@@ -2229,10 +2233,10 @@ const Shell = struct {
break;
};
}
- const paced = s.test_clock == null and s.core.continuous();
+ const paced = s.test_clock == null and s.moving();
var tick: u64 = 0;
if (paced) {
- const period = pardes.animation.frame_ns;
+ const period = pardes.frame_ns;
const now: u64 = @intCast(std.Io.Clock.awake.now(s.io).nanoseconds);
tick = if (s.pace_ns != 0 and now -| s.pace_ns < 2 * period) s.pace_ns + period else now;
if (tick < now) tick += (now - tick) / period * period;
@@ -2266,7 +2270,7 @@ const Shell = struct {
while (!paced and s.output_seen and !s.input_seen and !s.core.quit and s.test_clock == null) {
if (s.input_ns > s.drawn_ns) break;
if (s.focused_ns > s.drawn_ns and s.focused_ns -| s.input_ns < std.time.ns_per_s) break;
- const due = s.drawn_ns + pardes.animation.frame_ns;
+ const due = s.drawn_ns + pardes.frame_ns;
const now: u64 = @intCast(std.Io.Clock.awake.now(s.io).nanoseconds);
if (now + std.time.ns_per_ms > due) break;
s.waitOnce(@intCast((due - now) / std.time.ns_per_ms));
@@ -2280,9 +2284,9 @@ const Shell = struct {
break :held held;
} else next: {
if (wait != 0) {
- // A virtual clock moves a frame a wake while anything moves
- // continuously (the glide), as the real one would.
- s.wake_to = s.core.nextWake() orelse if (s.core.continuous()) s.core.now_ns + pardes.animation.frame_ns else 0;
+ // A virtual clock moves a frame a wake while the tty's own
+ // motions move (the glide), as the real one would.
+ s.wake_to = s.core.nextWake() orelse if (s.moving()) s.core.now_ns + pardes.frame_ns else 0;
requestWake(s.io, wait);
}
pardes.turn.rest();
@@ -2567,17 +2571,22 @@ const Shell = struct {
s.loop.postEvent(.files_changed) catch {};
}
- /// ponytail: a terminal's scrollback under the wheel lands here (the
- /// wheel reaches the core as a mouse event, not counted as the GUI's
- /// notches are); `wheeled` from the mouse event if it should glide.
- fn stepGlide(ctx: ?*anyopaque) void {
+ /// The tty's own motions (its glide, a jump's trail) are under way.
+ fn moving(s: *const Shell) bool {
+ const sc = s.term() orelse return false;
+ return sc.glide.moving() or sc.trail.active;
+ }
+
+ /// The tty's own motions draw their frames themselves: the last frame
+ /// again, moved on, when the core has none to draw.
+ fn ownFrame(ctx: ?*anyopaque) void {
const s = of(ctx);
- if (s.term()) |sc| sc.glide.step(s.core, s.gpa, null, null);
+ if (s.moving() and !s.core.needs_frame and s.core.surface.cells.len != 0) present(ctx, &s.core.surface);
}
fn pollFrame(ctx: ?*anyopaque) void {
const s = of(ctx);
- stepGlide(ctx);
+ defer ownFrame(ctx);
if (s.fs) |f| if (f.tick().pending) {
_ = s.loop.tryPostEvent(.fs_ready) catch {};
};
@@ -2611,15 +2620,14 @@ const Shell = struct {
_ = s.frame.reset(.retain_capacity);
const tz_cells = tracy.zone(@src(), "surface->vaxis");
const win = vx.window();
- if (sc.glide.pending) sc.glide.measure(s.gpa, canonical);
- if (sc.glide.moving()) sc.glide.advance(s.core.now_ns, sc.glide.motion);
+ // The tty's own motions, on its own clock, from the frame alone.
+ const now: u64 = s.test_clock orelse @intCast(std.Io.Clock.awake.now(s.io).nanoseconds);
+ sc.glide.frame(s.gpa, canonical, now, null, null);
s.core.frames.scroll = @round(sc.glide.follow.offset);
const glided = glideRows(s.frame.allocator(), canonical, &sc.glide) catch canonical;
const truecolor = vx.caps.rgb or colortermTruecolor();
- const trail_on = s.core.settings.jump_trail and truecolor and s.core.settings.motion != .off;
- const shown = trailCells(s.frame.allocator(), glided, &sc.trail, trail_on, s.test_clock orelse @intCast(std.Io.Clock.awake.now(s.io).nanoseconds)) catch glided;
- // Each of the shell's own motions asks for frames while it runs.
- s.core.shell_continuous = sc.glide.moving() or sc.trail.active;
+ const trail_on = s.core.settings.jump_trail and truecolor;
+ const shown = trailCells(s.frame.allocator(), glided, &sc.trail, trail_on, now) catch glided;
paintCells(win, shown.cells, shown.cols, shown.rows);
if (s.remote) |c| if (c.link.notice_len > 0) noticeLine(win, c.link.notice(), shown.cols, shown.rows);
tz_cells.end();
@@ -3519,21 +3527,18 @@ test "the tty draws a glide at whole rows: once a flick or a spin slows, its ste
defer text.deinit(gpa);
for (0..3000) |i| try text.print(gpa, "{d:0>5} line\n", .{i});
_ = try core.setTestFile(text.items);
- core.settings.motion = .smooth;
var arena: std.heap.ArenaAllocator = .init(gpa);
defer arena.deinit();
var glide: pardes.glide.Glide = .{};
defer glide.deinit(gpa);
var now: u64 = std.time.ns_per_s;
- // One tick of the tty: its loop step, the frame, the picture.
+ // One tick of the tty: the frame, the picture.
const tick = struct {
fn f(c: *pardes.Pardes, g: *pardes.glide.Glide, a: *std.heap.ArenaAllocator, t: u64) !i32 {
c.advance(t);
- g.step(c, std.testing.allocator, null, null);
_ = a.reset(.retain_capacity);
const s = try c.render(a.allocator());
- if (g.pending) g.measure(std.testing.allocator, s);
- if (g.moving()) g.advance(t, g.motion);
+ g.frame(std.testing.allocator, s, t, null, null);
_ = try glideRows(a.allocator(), s, g);
return @intFromFloat(@round(g.follow.offset));
}
@@ -3543,19 +3548,19 @@ test "the tty draws a glide at whole rows: once a flick or a spin slows, its ste
for (0..notches) |i| {
core.update(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = 20, .row = 10 } });
if (i % 2 == 1) {
- now += pardes.animation.frame_ns;
+ now += pardes.frame_ns;
_ = try tick(core, &glide, &arena, now);
}
}
- var drawn = try tick(core, &glide, &arena, now + pardes.animation.frame_ns);
- now += pardes.animation.frame_ns;
+ var drawn = try tick(core, &glide, &arena, now + pardes.frame_ns);
+ now += pardes.frame_ns;
var last_step: i32 = std.math.maxInt(i32);
var last_gap: usize = 0;
var since: usize = 0;
var ticks: usize = 0;
while (glide.moving()) : (ticks += 1) {
try std.testing.expect(ticks < 200);
- now += pardes.animation.frame_ns;
+ now += pardes.frame_ns;
const k = try tick(core, &glide, &arena, now);
const step = k - drawn;
drawn = k;
@@ -3584,7 +3589,7 @@ test "the tty draws a glide at whole rows: once a flick or a spin slows, its ste
const row = (core.surface.cursor orelse return error.NoCursor).y;
for (0..20) |i| {
if (i % 2 == 0) keys.j(core);
- now += pardes.animation.frame_ns;
+ now += pardes.frame_ns;
_ = try tick(core, &glide, &arena, now);
const shown = try glideRows(arena.allocator(), &core.surface, &glide);
try std.testing.expectEqual(row, (shown.cursor orelse return error.NoCursor).y);