diff options
Diffstat (limited to 'src/tui')
| -rw-r--r-- | src/tui/tui.zig | 62 |
1 files changed, 37 insertions, 25 deletions
diff --git a/src/tui/tui.zig b/src/tui/tui.zig index 919eeded..6d323183 100644 --- a/src/tui/tui.zig +++ b/src/tui/tui.zig @@ -758,30 +758,34 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8, while (!link.quit) { // Its predicted echo judged and caught up, once a frame. if (r.echoFrame()) link.dirty = true; - if (link.dirty) client_link.draw(&sh); - // The tty's own motions (its glide, a jump's trail) drawn a frame - // a tick while they move, as waitInput wakes the local loop: a - // wheel's glide was drawn only at the next event. After the - // draw, which starts a glide, and after the last iteration's - // wakes, as the latest asked for is the one kept. - if (sh.moving()) { - link.dirty = true; - requestWake(io, @intCast(pardes.frame_ns / std.time.ns_per_ms)); - } - const first = (loop.tryEvent() catch null) orelse idle: { - // Idle, its frame drawn: the next key needs no copy taken. - r.ready(); - break :idle loop.nextEvent() catch break; - }; - var ev = first; - var batch: usize = 1; - while (true) { - _ = sh.apply(ev); - if (link.quit or (!sh.in_paste and batch >= 64)) break; - ev = (loop.tryEvent() catch null) orelse break; - batch += 1; + if (link.dirty) { + client_link.draw(&sh); + } else if (sh.moving() and r.core().surface.cells.len != 0) { + // 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; + link.again += 1; } + // Idle, its frame drawn: the next key needs no copy taken. + if (loop.tryEvent() catch null) |ev| sh.held = ev else r.ready(); + // The session's own wait: an input drawn at once, the session's + // units and deltas a frame a tick at most, the tty's own motions + // on its grid of ticks; predictions judged a frame at a time. + var wait: u32 = if (r.echo.n > 0 or r.echo.cursor != null or r.echo.nd > 0) @intCast(pardes.frame_ns / std.time.ns_per_ms) else 0; + if (link.quietCheck()) |ms| wait = if (wait == 0) ms else @min(wait, ms); + Shell.waitInput(&sh, wait); r.settle(); + // A rollback since it drew (`toConfirmed`): its frame is drawn + // again, never moved on from cells the copy put back. + if (r.moved) { + r.moved = false; + link.dirty = true; + } if (screen.caps_pending and screen.vx.queries_done.load(.unordered)) { screen.caps_pending = false; screen.vx.enableDetectedFeatures(screen.tty.writer()) catch {}; @@ -789,9 +793,6 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8, link.dirty = true; } 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.frame_ns / std.time.ns_per_ms)); - if (link.quietCheck()) |ms| requestWake(io, ms); if (r.diverged != null) link.quit = true; } if (init.environ_map.get("PARDES_REPLICA_STATS")) |file| link.writeStats(file); @@ -1604,6 +1605,7 @@ const Shell = struct { pardes.turn.rest(); const got = s.loop.nextEvent() catch { pardes.turn.wake(); + if (s.client) |c| c.link.quit = true; s.core.quit = true; return s.reloadWatched(); }; @@ -1729,6 +1731,16 @@ const Shell = struct { }, .replica_mail => s.input_seen = true, .said => |said| if (s.client) |c| { + // The session's units and deltas are a client's output + // (waitInput paces it): a terminal's delta, or the unit + // that answers its own input, is its echo, drawn at once. + s.output_seen = true; + const echo = switch (said) { + .screen => true, + .unit => |b| if (replica.parseUnit(b)) |u| u.origin == c.link.r.id else false, + else => false, + }; + if (echo) s.focused_ns = @intCast(std.Io.Clock.awake.now(s.io).nanoseconds); c.link.take(said); if (said == .refused) return true; } else switch (said) { |
