diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-19 04:25:24 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-19 05:01:46 -0300 |
| commit | 0a9546f1d206f4ab55063e1c26c668e9626b3929 (patch) | |
| tree | ff4d8128136e67c02451e14744359269dd954f8e /core | |
| parent | 5e2f518d70b1ed7e2e1468852fd34c77af72209a (diff) | |
| download | pardes-0a9546f1d206f4ab55063e1c26c668e9626b3929.tar.gz pardes-0a9546f1d206f4ab55063e1c26c668e9626b3929.zip | |
core: a far client's pane switch beside a shell that asked for focus events is instant (the reorganisation's 12b, the design round's answer 1; the user's rulings P14 and P16: motions and layout instant far away): `update` and a 9P request end in reportFocus, which tells a program that asked (DECSET 1004) that its pane took or gave up the keyboard, a pty write, so on a client every switch into or out of such a shell (a click, Up, Del of the pane beside it, Esc or Last out of it, a word that opens a pane, the window's keyboard lost) stopped at `pty_write` and waited a round trip; now a client's own step (screen-state, speculating) records what it told and writes nothing, and the session's step makes the write, off the tape on both sides already (tape.hostCall's pty_write), so the switch shows at once and the program hears of it a round trip later; a write parked behind an earlier one (`pending_write`, digested) would differ between the two and is not handled: it needs the shell's queue full at the switch; the three `pty_write` rows of `may_wait` that item 1 listed for it are gone (the walk named them stale), and a test at the end of core/replica.zig (a client's click into the shell applied at once, the session's two units confirming it fast, the program told `CSI I` once, no misprediction), shown failing without the change (stopped 1); with 12a's Recent stat put back the walk now names Del, DelAbove, DelBelow and Delcol of a file pane at `kind` (7 unlisted); the semantics word did not move; tui core-test 832/975 (143 skipped), shell-test 1010/1013, pane-test 183/184, behaviour-test 275/275 and --replay 275/275, process-test 2 of 144 failed (lspcomplete, lspcompletemoved, the base's), replicas --clients 5 diverged 0 unequal 0 deltas wrong 0 (1827/0, 1596/0, 1803/0) quiet differ 0 (422/0, 563/0, 655/0) at 30/80/207 ms, stopped 89/73/108, mispredicted 37/34/36 (the soak's shells ask no focus events), gui unit-test 1608/1612 (its perf check's BaselineHarnessMismatch the base's), daemon.py plain, --far, --games, --window-clients pass; gate-w seam-b-2 against tree1: 77/77 frames byte-identical in Debug, its unit-test 1608/1612, perfab corpus2x -0.044% (pictures identical in all 10 runs), perfops 97 counts within 0.1% (largest +0.0095%, image-frame on large)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core')
| -rw-r--r-- | core/Core.zig | 7 | ||||
| -rw-r--r-- | core/replica.zig | 58 |
2 files changed, 59 insertions, 6 deletions
diff --git a/core/Core.zig b/core/Core.zig index b8ca9439..2036fd77 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -898,11 +898,16 @@ fn reportFocus(p: *Pardes) void { break :blk .{ .id = v.active, .serial = pane.serial }; }; if (std.meta.eql(want, v.focus_told)) return; + defer v.focus_told = want; + // A client's own step records what it told and writes nothing: the + // session's step makes the write, off the tape on both sides + // (tape.hostCall's pty_write), so the switch shows at once and the + // program hears of it a round trip later. + if (tape.speculating() and tape.screenState()) return; if (v.focus_told) |old| if (p.panes[old.id]) |pane| { if (pane.serial == old.serial and pardes.Term.modes(pane.terminal).focus) p.emitWrite(old.id, "\x1b[O"); }; if (want) |new| if (pardes.Term.modes(p.panes[new.id].?.terminal).focus) p.emitWrite(new.id, "\x1b[I"); - v.focus_told = want; } pub fn emitWrite(p: *Pardes, id: usize, bytes: []const u8) void { diff --git a/core/replica.zig b/core/replica.zig index 479ee7c6..ab805cda 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -5266,11 +5266,6 @@ const may_wait = [_]struct { what: []const u8, on: On, stop: []const u8, why: [] // A shell's program has the keys: what reaches it is its input (a far // shell may feel like ssh). .{ .what = "*", .on = .shell, .stop = "pty_write", .why = "a key into a shell's program" }, - // The focus report (DECSET 1004): a pane switch into or out of a shell - // whose program asked tells it, a pty write at the end of `update`. - .{ .what = "*", .on = .file, .stop = "pty_write", .why = "the focus report to the shell beside" }, - .{ .what = "*", .on = .kind, .stop = "pty_write", .why = "the focus report to the shell beside" }, - .{ .what = "*", .on = .shell_normal, .stop = "pty_write", .why = "the focus report to the shell" }, // A file from the session's disk (P14). .{ .what = "Look *", .on = .any, .stop = "resolve", .why = "a name looked for on the session's disk" }, .{ .what = "LookNext", .on = .any, .stop = "resolve", .why = "a Look's walk: each word asked of the disk" }, @@ -5597,3 +5592,56 @@ test "a far client's every word and key, on a file's pane, a kind's and a shell' try std.testing.expectEqual(@as(u32, 0), unlisted); try std.testing.expectEqual(@as(u32, 0), stale); } + +test "a far client's click into a shell whose program asked for focus events is instant: the session's step tells the program, a round trip later, and the client's guess is confirmed" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell + const gpa = std.testing.allocator; + const Told = struct { + var bytes: [64]u8 = undefined; + var len: usize = 0; + fn write(_: ?*anyopaque, _: u8, b: []const u8) void { + @memcpy(bytes[len..][0..b.len], b); + len += b.len; + } + const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .pty_write = write }; + }; + Told.len = 0; + const a = try Authority.init(gpa, .{ .cols = 120, .rows = 40, .boot = .tty }, .{ .vtable = &Told.vtable }, true); + defer a.deinit(); + const shell: u8 = for (a.core.panes, 0..) |slot, id| { + if (slot) |pane| if (pane.isTerminal()) break @intCast(id); + } else return error.NoShell; + a.output(.{ .output = .{ .pane = shell, .bytes = "\x1b[?1004h$ " } }); + _ = (try a.pending()).?; + _ = try a.local(.{ .command = "New" }); + var screens: Screens = .init(gpa); + defer screens.deinit(a.core); + const peer = try screens.addPeer(); + const r = try joinedFresh(a); + defer r.deinit(); + try deliver(a, &screens, peer, r, .flush); + r.settle(); + Told.len = 0; + const rect = r.core().view().rects[shell]; + const row = rect.y + r.core().panes[shell].?.tag_rows + 1; + var sent: std.ArrayListUnmanaged([]u8) = .empty; + defer { + for (sent.items) |m| gpa.free(m); + sent.deinit(gpa); + } + for ([_]pardes.Mouse.Kind{ .press, .release }) |kind| try sent.append(gpa, try gpa.dupe(u8, try r.input(.{ .mouse = .{ .button = .left, .kind = kind, .col = rect.x + 2, .row = row } }))); + try std.testing.expectEqual(@as(u32, 0), r.stats.stopped); + try std.testing.expectEqual(@as(usize, shell), r.core().view().active); + for (sent.items) |m| { + try deliver(a, &screens, peer, r, .flush); + const u = try gpa.dupe(u8, try a.take(m)); + defer gpa.free(u); + try deliver(a, &screens, peer, r, .fill); + r.confirm(u); + r.settle(); + } + try std.testing.expectEqualStrings("\x1b[I", Told.bytes[0..Told.len]); + try std.testing.expectEqual(@as(u32, 0), r.stats.mispredicted); + try std.testing.expectEqual(@as(u32, 2), r.stats.fast); + try agrees(a, r); +} |
