summaryrefslogtreecommitdiff
path: root/src/tty
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-24 15:23:45 -0300
committerGabriel Schneider <[email protected]>2026-10-24 21:00:32 -0300
commita9e33e52d789c7433da1da17a8c82093c9114243 (patch)
tree0fb83bc2be369b5a36c86ce8173fb9114503528b /src/tty
parente28b0992e9cd8dcedea5ed435566277ee6a93d5b (diff)
downloadpardes-a9e33e52d789c7433da1da17a8c82093c9114243.tar.gz
pardes-a9e33e52d789c7433da1da17a8c82093c9114243.zip
anim 7: what the probe found: the paced wait spins (asleep, the CPU's clock fell and an input's frame took 2-5x as long), a glide measures the core's line count first and emits only the rows it shows, a far jump paints only its view, a long line 16 KB round the caret, the caret's sideways scroll measured from the view's edge, a paint never joined on the loop nor asked while the view stands still, rewritten generated panes do not glide, pictures decode off the loop
Diffstat (limited to 'src/tty')
-rw-r--r--src/tty/tty.zig38
1 files changed, 32 insertions, 6 deletions
diff --git a/src/tty/tty.zig b/src/tty/tty.zig
index 264cfbef..b7bb2d54 100644
--- a/src/tty/tty.zig
+++ b/src/tty/tty.zig
@@ -1521,8 +1521,10 @@ const Shell = struct {
/// PARDES_TEST_CLOCK's virtual time (host_io.testClock), and where the
/// running-out wait moves it: the core's next wake.
test_clock: ?u64 = null,
- /// The tick the last paced frame was due at (waitInput).
+ /// The tick the last paced frame was due at (waitInput), and whether
+ /// this wait read an input (its frame is drawn at once).
pace_ns: u64 = 0,
+ input_seen: bool = false,
wake_to: u64 = 0,
fn of(ctx: ?*anyopaque) *Shell {
@@ -1574,7 +1576,6 @@ const Shell = struct {
fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void {
const s = of(ctx);
- var batch: usize = 0;
// 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
@@ -1583,14 +1584,32 @@ const Shell = struct {
// ends the wait at once and its frame is drawn then; the ticks after
// it run from it.
var wait = timeout_ms;
- if (s.test_clock == null and s.core.continuous()) {
+ const paced = s.test_clock == null and s.core.continuous();
+ var tick: u64 = 0;
+ if (paced) {
const period = pardes.animation.frame_ns;
const now: u64 = @intCast(std.Io.Clock.awake.now(s.io).nanoseconds);
- var tick = if (s.pace_ns != 0 and now -| s.pace_ns < 2 * period) s.pace_ns + period else now;
+ 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;
s.pace_ns = tick;
wait = @intCast(@max(1, (tick -| now) / std.time.ns_per_ms));
}
+ s.input_seen = false;
+ // Paced, what is not an input (a frame's ack, a pty's output) is
+ // taken in and the wait goes on to the tick: the acks alone ran the
+ // loop at the terminal's round trip.
+ while (true) {
+ s.waitOnce(wait);
+ if (!paced or s.input_seen or s.core.quit) break;
+ const now: u64 = @intCast(std.Io.Clock.awake.now(s.io).nanoseconds);
+ if (now + std.time.ns_per_ms > tick) break;
+ wait = @intCast((tick - now) / std.time.ns_per_ms);
+ }
+ if (paced and s.input_seen) s.pace_ns = @intCast(std.Io.Clock.awake.now(s.io).nanoseconds);
+ }
+
+ fn waitOnce(s: *Shell, wait: u32) void {
+ var batch: usize = 0;
if (wait != 0) {
s.wake_to = s.core.nextWake() orelse 0;
requestWake(s.io, wait);
@@ -1638,8 +1657,15 @@ const Shell = struct {
// A key's or a click's time, for its latency to the frame that
// answers it (FrameStats): when the loop takes it in.
switch (event) {
- .key_press => core.frames.input(pardes.FrameStats.nowNs()),
- .mouse => |m| if (m.type == .press) core.frames.input(pardes.FrameStats.nowNs()),
+ .key_press => {
+ core.frames.input(pardes.FrameStats.nowNs());
+ s.input_seen = true;
+ },
+ .mouse => |m| if (m.type == .press) {
+ core.frames.input(pardes.FrameStats.nowNs());
+ s.input_seen = true;
+ },
+ .paste, .paste_start, .winsize => s.input_seen = true,
else => {},
}
switch (event) {