summaryrefslogtreecommitdiff
path: root/dev/tui
diff options
context:
space:
mode:
Diffstat (limited to 'dev/tui')
-rw-r--r--dev/tui/tui.zig85
1 files changed, 50 insertions, 35 deletions
diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig
index 71a87f29..5903e448 100644
--- a/dev/tui/tui.zig
+++ b/dev/tui/tui.zig
@@ -624,23 +624,16 @@ const Client = struct {
link: replica.Link,
/// The client's own view drawn on its terminal, outside any step: the
- /// replica's digest stays the session's (views.drawOne). What the host
- /// writes in the core as it presents (a frame skipped, one owed) is put
- /// back, as the frame statistics are this process's.
+ /// replica's digest stays the session's (views.drawOne); the frame
+ /// statistics are this process's (`Shell.frames`).
fn draw(c: *Client, s: *Shell) void {
- const r = c.link.r;
- const core = r.core();
- const skipped = core.present_skipped;
- const needs = core.needs_frame;
- core.frames.mark_start = pardes.FrameStats.nowNs();
- core.frames.mark_update = core.frames.mark_start;
- r.draw(.{ .ctx = s, .f = Shell.present });
- core.frames.mark_render = core.frames.mark_update;
- const drew = core.frames.bytes > 0;
- c.link.owed = core.present_skipped;
- core.frames.record(pardes.FrameStats.nowNs(), false, c.link.owed);
- core.present_skipped = skipped;
- core.needs_frame = needs;
+ const frames = s.frames;
+ frames.mark_start = pardes.FrameStats.nowNs();
+ frames.mark_update = frames.mark_start;
+ c.link.owed = !c.link.r.draw(.{ .ctx = s, .f = Shell.present });
+ frames.mark_render = frames.mark_update;
+ const drew = frames.bytes > 0;
+ frames.record(pardes.FrameStats.nowNs(), false, c.link.owed);
c.link.drawn(drew);
}
};
@@ -696,6 +689,9 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8,
o.image_allocator = allocs.image;
var distrusted: pardes.Addon.Distrusted = .{};
o.distrusted = &distrusted;
+ // Its frame timings, this process's (Pardes.frames).
+ var frames: pardes.FrameStats = .{};
+ o.frames = &frames;
var joined: replica.Joined = undefined;
var r = replica.join(gpa, &joined, path, session, o, have, &why, null) orelse Said.no(io, "{s}", .{std.mem.sliceTo(&why, 0)});
@@ -729,6 +725,7 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8,
.gpa = gpa,
.lsp_gpa = allocs.lsp,
.core = r.core(),
+ .frames = &frames,
.prompt_rcs = undefined,
.loop = &loop,
.frame = &frame_arena,
@@ -768,11 +765,8 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8,
// The tty's own motions (its glide, a jump's trail): the last
// frame again, moved on, as the session's terminal draws them
// (`ownFrame`), not rendered again. One the terminal's answer
- // holds is skipped (the next tick's moves on): nothing of it
- // is written in the core, as `Client.draw` puts it back.
- const skipped = r.core().present_skipped;
- Shell.present(&sh, &r.core().surface);
- r.core().present_skipped = skipped;
+ // holds is skipped (the next tick's moves on).
+ _ = Shell.present(&sh, &r.core().surface);
link.again += 1;
}
// Idle, its frame drawn: the next key needs no copy taken.
@@ -982,6 +976,9 @@ fn localSession(
options.image_allocator = allocs.image;
options.tree_sitter_allocator = allocs.tree_sitter;
options.frame_allocator = allocs.frame;
+ // Its frame timings, the terminal's to write as it draws (Pardes.frames).
+ var frames: pardes.FrameStats = .{};
+ options.frames = &frames;
host_io.startWorkers(allocs);
defer host_io.stopWorkers();
@@ -1010,6 +1007,7 @@ fn localSession(
.gpa = gpa,
.lsp_gpa = allocs.lsp,
.core = core,
+ .frames = &frames,
.prompt_rcs = &prompt_rcs,
.loop = loop,
.frame = &frame_arena,
@@ -1202,6 +1200,9 @@ const Shell = struct {
gpa: std.mem.Allocator,
lsp_gpa: std.mem.Allocator,
core: *pardes.Pardes,
+ /// Its runner's frame timings (Pardes.frames): written as it draws and
+ /// takes input, never through the core.
+ frames: *pardes.FrameStats,
prompt_rcs: *const host_io.Shell.PromptFiles,
loop: *Loop,
/// The terminal (none in tests), and the view it shows: a second
@@ -1255,6 +1256,9 @@ const Shell = struct {
took_input: bool = false,
took_output: bool = false,
held: ?Msg = null,
+ /// A frame of the tty's own motions was held (`ownFrame`): the core's
+ /// next is owed too (`presentFrame`).
+ own_skipped: bool = false,
/// This process a replica client of a session elsewhere (`runClient`):
/// its inputs go to the replica, never straight to the core.
client: ?*Client = null,
@@ -1290,7 +1294,7 @@ const Shell = struct {
const isolated_vtable: host_io.Host.VTable = .{
.wait_input = waitInput,
.now = clockNow,
- .present = present,
+ .present = presentFrame,
.post_present = postPresent,
.poll_frame = ownFrame,
};
@@ -1298,7 +1302,7 @@ const Shell = struct {
const vtable: host_io.Host.VTable = .{
.wait_input = waitInput,
.now = clockNow,
- .present = present,
+ .present = presentFrame,
.post_present = postPresent,
.poll_frame = pollFrame,
.watched = watched,
@@ -1689,11 +1693,11 @@ const Shell = struct {
// answers it (FrameStats): when the loop takes it in.
switch (event) {
.key_press => {
- core.frames.input(pardes.FrameStats.nowNs());
+ s.frames.input(pardes.FrameStats.nowNs());
s.input_seen = true;
},
.mouse => |m| if (m.type == .press) {
- core.frames.input(pardes.FrameStats.nowNs());
+ s.frames.input(pardes.FrameStats.nowNs());
s.input_seen = true;
},
.paste, .paste_start, .winsize => s.input_seen = true,
@@ -1903,7 +1907,9 @@ const Shell = struct {
/// again, moved on, when the core has none to draw.
fn ownFrame(ctx: ?*anyopaque) void {
const s = of(ctx);
- if (s.moving() and !s.core.needs_frame and s.core.surface.cells.len != 0) present(ctx, &s.core.surface);
+ if (s.moving() and !s.core.needs_frame and s.core.surface.cells.len != 0) {
+ if (!present(ctx, &s.core.surface)) s.own_skipped = true;
+ }
}
fn pollFrame(ctx: ?*anyopaque) void {
@@ -1929,16 +1935,22 @@ const Shell = struct {
}
}
- fn present(ctx: ?*anyopaque, canonical: *const pardes.Surface) void {
+ /// The core's frame (Host.present): owed too when a frame of the
+ /// tty's own motions (`ownFrame`) was held since the last.
+ fn presentFrame(ctx: ?*anyopaque, canonical: *const pardes.Surface) bool {
const s = of(ctx);
- const sc = s.term() orelse return;
+ const shown = present(ctx, canonical);
+ defer s.own_skipped = false;
+ return shown and !s.own_skipped;
+ }
+
+ fn present(ctx: ?*anyopaque, canonical: *const pardes.Surface) bool {
+ const s = of(ctx);
+ const sc = s.term() orelse return true;
const vx = &sc.vx;
// The last frame is not answered yet: this one stays owed, and the
// answer's wake draws the state as it is then.
- if (sc.feed.ack.holds(@intCast(std.Io.Clock.awake.now(s.io).nanoseconds), s.io)) {
- s.core.present_skipped = true;
- return;
- }
+ if (sc.feed.ack.holds(@intCast(std.Io.Clock.awake.now(s.io).nanoseconds), s.io)) return false;
_ = s.frame.reset(.retain_capacity);
const tz_cells = tracy.zone(@src(), "surface->vaxis");
const win = vx.window();
@@ -1949,10 +1961,10 @@ const Shell = struct {
const cell_h = terminalCellPixels(vx.screen.height_pix, vx.screen.height, 16);
const arted = sc.art.frame(s.gpa, s.frame.allocator(), canonical, vx.caps.kitty_graphics, cell_h) catch canonical;
sc.glide.frame(s.gpa, arted, now, null, null);
- s.core.frames.scroll = @round(sc.glide.follow.offset);
+ s.frames.scroll = @round(sc.glide.follow.offset);
const glided = glideRows(s.frame.allocator(), arted, &sc.glide) catch arted;
const truecolor = vx.caps.rgb or colortermTruecolor();
- const trail_on = s.core.settings.jump_trail and truecolor;
+ const trail_on = canonical.facts.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.client) |c| if (c.link.notice_len > 0) noticeLine(win, c.link.notice(), shown.cols, shown.rows);
@@ -2038,10 +2050,11 @@ const Shell = struct {
vx.render(sc.tty.writer()) catch {};
// The frame's cost to the terminal (FrameStats.Frame.bytes): what
// vaxis's diff of the cells wrote.
- s.core.frames.bytes +|= @intCast(@min(std.math.maxInt(u32), sc.tty.tty_writer.pos + sc.tty.writer().end -| before));
+ s.frames.bytes +|= @intCast(@min(std.math.maxInt(u32), sc.tty.tty_writer.pos + sc.tty.writer().end -| before));
if (sc.tty.tty_writer.pos + sc.tty.writer().end != before) sc.feed.ack.ask(sc.tty.writer(), @intCast(std.Io.Clock.awake.now(s.io).nanoseconds));
s.drawn_ns = @intCast(std.Io.Clock.awake.now(s.io).nanoseconds);
tz_render.end();
+ return true;
}
fn postPresent(ctx: ?*anyopaque) void {
@@ -3016,6 +3029,7 @@ test "TTY queued results reject old PTY generations and LSP request IDs" {
.gpa = gpa,
.lsp_gpa = gpa,
.core = core,
+ .frames = core.frames,
.prompt_rcs = undefined,
.loop = undefined,
.frame = undefined,
@@ -3061,6 +3075,7 @@ test "TTY worker setup failures finish matching LSP and pipe requests" {
.gpa = failing.allocator(),
.lsp_gpa = failing.allocator(),
.core = core,
+ .frames = core.frames,
.prompt_rcs = undefined,
.loop = undefined,
.frame = undefined,