summaryrefslogtreecommitdiff
path: root/core/replica.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/replica.zig')
-rw-r--r--core/replica.zig57
1 files changed, 29 insertions, 28 deletions
diff --git a/core/replica.zig b/core/replica.zig
index 625153d1..3f04b3bc 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -2278,7 +2278,7 @@ pub const Peers = struct {
if (ps.next_id == 0) ps.next_id = 1;
// The session's digest as dumped, for the joiner to check its load by.
const digest = tape.digestOf(core);
- peer.welcome_len = (wire.encodeServer(&peer.welcome, .{ .welcome = .{ .pid = @intCast(libc.getpid()), .session = ps.name[0..@min(ps.name.len, wire.max_name)], .client = peer.id, .view = k, .dump_len = whole, .gmtoff = gmtoff(), .digest = digest, .semantics = wire.semantics, .blobs = @intCast(blobs.items.len) } }) catch unreachable).len;
+ peer.welcome_len = (wire.encodeServer(&peer.welcome, .{ .welcome = .{ .pid = @intCast(libc.getpid()), .session = ps.name[0..@min(ps.name.len, wire.max_name)], .client = peer.id, .view = .at(k), .dump_len = whole, .gmtoff = gmtoff(), .digest = digest, .semantics = wire.semantics, .blobs = @intCast(blobs.items.len) } }) catch unreachable).len;
if (ps.threads) peer.writer = std.Thread.spawn(.{}, Peer.writeLoop, .{peer}) catch null;
if (ps.threads) peer.reader = std.Thread.spawn(.{}, Peer.readLoop, .{peer}) catch null;
if (ps.threads and (peer.writer == null or peer.reader == null)) {
@@ -2591,7 +2591,7 @@ fn joinOn(gpa: Allocator, fd: c_int, session: []const u8, why: []u8, have: ?*Hav
.welcome => |w| {
r.j.pid = w.pid;
r.j.client = w.client;
- r.j.view = w.view;
+ r.j.view = w.view.index();
r.j.gmtoff = w.gmtoff;
r.j.digest = w.digest;
r.j.semantics = w.semantics;
@@ -3292,7 +3292,7 @@ const TestHost = struct {
/// A host with ptys whose pump polls for a frame, as a client's does.
const PtyHost = struct {
- fn resized(_: ?*anyopaque, _: u8, _: u16, _: u16) void {}
+ fn resized(_: ?*anyopaque, _: pardes.Pane.Id, _: u16, _: u16) void {}
fn poll(_: ?*anyopaque) void {}
const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .pty_resize = resized, .poll_frame = poll };
fn host() pardes.Host {
@@ -3729,7 +3729,7 @@ test "a delta applied under a speculation outlives its rollback: the terminal st
for (0..3) |round| {
// The shell prints: its unit rolls the replica back and applies the
// key again; then its delta lands, under the new copy.
- for (0..40) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "round {d} line {d}\r\n", .{ round, i }) } });
+ for (0..40) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "round {d} line {d}\r\n", .{ round, i }) } });
r.confirm((try a.pending()).?);
r.settle();
try std.testing.expect(r.copy.held);
@@ -3751,7 +3751,7 @@ test "a delta applied under a speculation outlives its rollback: the terminal st
r.confirm(try a.local(.{ .focus = false }));
_ = try pardes.edit.shellRows(r.core(), r.core().panes[shell].?);
try key(r, 'x', &sent);
- for (0..40) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "last line {d}\r\n", .{i}) } });
+ for (0..40) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "last line {d}\r\n", .{i}) } });
r.confirm((try a.pending()).?);
r.settle();
try deliver(a, &screens, peer, r, .flush);
@@ -3875,7 +3875,7 @@ test "a terminal sized again by a client's key: the step reads the grid it had,
// History the replica holds as holes, of lines a narrow grid wraps in
// two, which a wider one unwraps.
var line: [96]u8 = undefined;
- for (0..60) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "{d:0>4} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n", .{i}) } });
+ for (0..60) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "{d:0>4} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n", .{i}) } });
r.confirm((try a.pending()).?);
// Out of terminal mode in the session's view, which sizes it; then a
// client's own view (a copy of it), wider: its first key sizes the
@@ -3954,7 +3954,7 @@ test "pardes's own keys over a terminal's history apply at once: its view moves
a.core.view().active = shell;
r.confirm(try a.local(.{ .focus = true }));
var line: [64]u8 = undefined;
- for (0..200) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "history line {d}\r\n", .{i}) } });
+ for (0..200) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "history line {d}\r\n", .{i}) } });
r.confirm((try a.pending()).?);
try deliver(a, &screens, peer, r, .flush);
r.settle();
@@ -3977,7 +3977,7 @@ test "pardes's own keys over a terminal's history apply at once: its view moves
// The shell prints while they wait: its unit, then its delta, which
// sets the view the authority's (at the bottom still): what was applied
// goes on top of it again.
- for (0..5) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "late line {d}\r\n", .{i}) } });
+ for (0..5) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "late line {d}\r\n", .{i}) } });
r.confirm((try a.pending()).?);
r.settle();
try deliver(a, &screens, peer, r, .flush);
@@ -4043,7 +4043,7 @@ test "a unit kept over a copy taken ahead is never replayed over a delta that ca
a.core.view().active = shell;
r.confirm(try a.local(.{ .focus = true }));
var line: [96]u8 = undefined;
- for (0..30) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "line {d} {s}\r\n", .{ i, "words of a length its own"[0 .. i % 20 + 4] }) } });
+ for (0..30) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "line {d} {s}\r\n", .{ i, "words of a length its own"[0 .. i % 20 + 4] }) } });
r.confirm((try a.pending()).?);
try deliver(a, &screens, peer, r, .flush);
// Out of the shell's tty mode, in the session's view: keys over its text.
@@ -4061,8 +4061,8 @@ test "a unit kept over a copy taken ahead is never replayed over a delta that ca
r.settle();
}
// The program redraws the screen: other rows where those keys read.
- a.output(.{ .output = .{ .pane = shell, .bytes = "\x1b[H\x1b[2J" } });
- for (0..30) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "{d}\r\n", .{i}) } });
+ a.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b[H\x1b[2J" } });
+ for (0..30) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "{d}\r\n", .{i}) } });
r.confirm((try a.pending()).?);
r.settle();
try deliver(a, &screens, peer, r, .flush);
@@ -4174,7 +4174,7 @@ test "a replica joined from a dump replays a step that opens a file's pane and s
defer a.deinit();
var words: [64]pardes.Kind.LoadedWord = undefined;
const zon = pardes.Kind.loadedOf(&Zon.ops, "/x/zon.so", @splat(9), &words);
- _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &zon } });
+ _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &zon } });
const r = try joinedNow(a, 1, 0);
defer r.deinit();
try std.testing.expectEqual(digestOf(a), r.digest());
@@ -4703,7 +4703,7 @@ test "a step that reads a terminal's rows as the core keeps them sends a new cli
} else return error.NoShell;
a.core.view().active = shell;
var line: [64]u8 = undefined;
- for (0..60) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "line {d} of the shell's history\r\n", .{i}) } });
+ for (0..60) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "line {d} of the shell's history\r\n", .{i}) } });
const out = try gpa.dupe(u8, (try a.pending()).?);
defer gpa.free(out);
for ([_]*Replica{ r1, r2 }) |r| r.confirm(out);
@@ -4733,7 +4733,7 @@ test "a replica with no code for a kind whose state is not plain shows its pane
// replica's core takes the kind's words, never its code.
var words: [64]pardes.Kind.LoadedWord = undefined;
const counter = pardes.Kind.loadedOf(&Counter.ops, "/x/counter.so", @splat(7), &words);
- r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &counter } }));
+ r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &counter } }));
r.confirm(try a.local(.{ .command = "Counter" }));
try std.testing.expect(r.core().kinds.ops[r.core().kinds.n - 1] == null);
try std.testing.expect(try shows(r.core(), "addon counter 1 does not run in this client"));
@@ -4791,7 +4791,7 @@ test "a kind's place moved in a step of another view's: a replica's key that rea
defer r.deinit();
var words: [64]pardes.Kind.LoadedWord = undefined;
const placed = pardes.Kind.loadedOf(&Placed.ops, "/x/placed.so", @splat(7), &words);
- r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &placed } }));
+ r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &placed } }));
// The replica's view opens the kind's pane, and an Esc goes back to
// the file (Last): view 0 has the file.
const own = try a.openView(1);
@@ -4845,7 +4845,7 @@ test "a client joined from a dump numbers a kind's next job as the session does"
defer a.deinit();
var words: [64]pardes.Kind.LoadedWord = undefined;
const jobber = pardes.Kind.loadedOf(&Jobber.ops, "/x/jobber.so", @splat(7), &words);
- _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &jobber } });
+ _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &jobber } });
_ = try a.local(.{ .command = "Jobber" });
for (0..3) |_| _ = try a.local(.{ .key = .{ .cp = 'x', .text = "x" } });
const id = a.core.view().active;
@@ -4864,7 +4864,7 @@ test "a replica's word that opens a kind's pane with no file waits for the autho
defer r.deinit();
var words: [64]pardes.Kind.LoadedWord = undefined;
const placed = pardes.Kind.loadedOf(&Placed.ops, "/x/placed.so", @splat(7), &words);
- r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &placed } }));
+ r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &placed } }));
// Its replica has no code for the kind: the open's outcome (its place,
// `1:0 0`) is the authority's to say.
const msg = try gpa.dupe(u8, try r.input(.{ .command = "Placed" }));
@@ -4883,7 +4883,7 @@ test "a client joined from a dump tells a kind each view's facts as the session
defer a.deinit();
var words: [64]pardes.Kind.LoadedWord = undefined;
const placed = pardes.Kind.loadedOf(&Placed.ops, "/x/placed.so", @splat(7), &words);
- _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &placed } });
+ _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &placed } });
_ = try a.local(.{ .command = "Placed" });
// A message in its pane: a band over its body, in each view.
_ = try a.local(.{ .command = "Placed x" });
@@ -4937,7 +4937,8 @@ const Asker = struct {
const BusyHost = struct {
var core: ?*Pardes = null;
var tasks: @import("selection_pipe.zig").Tasks = .{ .len = @import("selection_pipe.zig").Tasks.capacity };
- fn job(_: ?*anyopaque, pane: u8, serial: u32, token: u32) void {
+ fn job(_: ?*anyopaque, id: pardes.Pane.Id, serial: u32, token: u32) void {
+ const pane = id.index();
pardes.host_io.KindJob.start(std.testing.io, core.?, &tasks, pane, serial, token, null, never);
}
fn never(_: ?*anyopaque, j: *pardes.host_io.KindJob) void {
@@ -4955,7 +4956,7 @@ test "a kind's job answered at once inside its host's call (no worker free) is t
defer r.deinit();
var words: [64]pardes.Kind.LoadedWord = undefined;
const asker = pardes.Kind.loadedOf(&Asker.ops, "/x/asker.so", @splat(7), &words);
- r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &asker } }));
+ r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &asker } }));
// The client has its code (as a library of its own found by its scan).
r.core().kinds.ops[r.core().kinds.byName("asker").?] = &Asker.ops;
r.confirm(try a.local(.{ .command = "Asker" }));
@@ -4981,7 +4982,7 @@ test "a closed terminal with a kitty image brought back on a client: its image d
} else return error.NoShell;
// A 2x2 picture in RGB (f=24): drawn, the emulator keeps it as RGBA
// of its own (TerminalImages.converted).
- a.output(.{ .output = .{ .pane = shell, .bytes = "\x1b_Ga=T,i=7,f=24,s=2,v=2;ESIzESIzESIzESIz\x1b\\" } });
+ a.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b_Ga=T,i=7,f=24,s=2,v=2;ESIzESIzESIzESIz\x1b\\" } });
r.confirm((try a.pending()).?);
// Closed and brought back: the client loads the session's dump of it,
// its image with it.
@@ -5034,7 +5035,7 @@ test "a far client's own Del of a pane whose kind's state is not plain, rolled b
defer a.deinit();
var words: [64]pardes.Kind.LoadedWord = undefined;
const counter = pardes.Kind.loadedOf(&Counter.ops, "/x/counter.so", @splat(7), &words);
- _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &counter } });
+ _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &counter } });
_ = try a.local(.{ .command = "Counter" });
// Joined from the dump: the kind's pane is a line here (no code), its
// slot the dump's.
@@ -5101,7 +5102,7 @@ const SeenHost = struct {
of(ctx).linked += 1;
}
fn watchTheme(_: ?*anyopaque, _: u32, _: bool) void {}
- fn watchFile(_: ?*anyopaque, _: u8, _: []const u8, _: bool, _: pardes.WatchMode) void {}
+ fn watchFile(_: ?*anyopaque, _: pardes.Pane.Id, _: []const u8, _: bool, _: pardes.WatchMode) void {}
const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .set_clipboard = setClipboard, .read_clipboard = readClipboard, .open_link = openLink, .watch_theme = watchTheme, .watch_file = watchFile };
fn host(h: *SeenHost) pardes.Host {
return .{ .ctx = h, .vtable = &vtable };
@@ -5256,7 +5257,7 @@ test "a client's n in a kind's pane is a motion: it steps to the next place a re
const dir = std.mem.span(@as([*:0]u8, @ptrCast(std.c.getcwd(&cwd, cwd.len) orelse return error.NoCwd)));
var words: [64]pardes.Kind.LoadedWord = undefined;
const still = pardes.Kind.loadedOf(&Still.ops, "/x/still.so", @splat(7), &words);
- _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &still } });
+ _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &still } });
// The kind's pane, its +Search (a place a row, as a kind's `/` leaves
// it), and a scratch whose words name files in the session's directory
// (as a command's output would).
@@ -5563,14 +5564,14 @@ test "a far client's every word and key, on a file's pane, a kind's and a shell'
if (slot) |pane| if (pane.isTerminal()) break id;
} else null;
if (shell) |id| {
- a.output(.{ .output = .{ .pane = @intCast(id), .bytes = "\x1b[?1004h$ " } });
+ a.output(.{ .output = .{ .pane = .at(id), .bytes = "\x1b[?1004h$ " } });
_ = (try a.pending()).?;
}
_ = try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}/mise.toml", .{dir}) });
const file = a.core.view().active;
var words: [64]pardes.Kind.LoadedWord = undefined;
const still = pardes.Kind.loadedOf(&Still.ops, "/x/still.so", @splat(7), &words);
- _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &still } });
+ _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &still } });
_ = try a.local(.{ .command = "Still" });
const kind = a.core.view().active;
try std.testing.expect(file != kind and a.core.panes[file].?.file != null and a.core.panes[kind].?.addon != null);
@@ -5670,7 +5671,7 @@ test "a far client's click into a shell whose program asked for focus events is
const Told = struct {
var bytes: [64]u8 = undefined;
var len: usize = 0;
- fn write(_: ?*anyopaque, _: u8, b: []const u8) void {
+ fn write(_: ?*anyopaque, _: pardes.Pane.Id, b: []const u8) void {
@memcpy(bytes[len..][0..b.len], b);
len += b.len;
}
@@ -5682,7 +5683,7 @@ test "a far client's click into a shell whose program asked for focus events is
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$ " } });
+ a.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b[?1004h$ " } });
_ = (try a.pending()).?;
_ = try a.local(.{ .command = "New" });
var screens: Screens = .init(gpa);