summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Core.zig7
-rw-r--r--core/replica.zig58
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);
+}