diff options
Diffstat (limited to 'src/tui')
| -rw-r--r-- | src/tui/tui.zig | 67 |
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); |
