summaryrefslogtreecommitdiff
path: root/runtime/macos.zig
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/macos.zig')
-rw-r--r--runtime/macos.zig51
1 files changed, 26 insertions, 25 deletions
diff --git a/runtime/macos.zig b/runtime/macos.zig
index cfe93b13..23d70b27 100644
--- a/runtime/macos.zig
+++ b/runtime/macos.zig
@@ -250,7 +250,7 @@ const State = struct {
io: std.Io,
core: *pardes.Pardes,
started: bool = false,
- runtime: Callbacks,
+ callbacks: Callbacks,
tag_cells: [pardes.MAX_TAG_LAYERS][]Cell = @splat(&.{}),
layer_cells: [pardes.MAX_PANES][]Cell = @splat(&.{}),
cells: []Cell = &.{},
@@ -290,9 +290,9 @@ const State = struct {
var state: ?State = null;
-export fn pardes_init(runtime: ?*const Callbacks, cols_arg: u16, rows_arg: u16) c_int {
+export fn pardes_init(callbacks: ?*const Callbacks, cols_arg: u16, rows_arg: u16) c_int {
if (state != null) return 1; // already up; deinit first
- initCore(runtime, cols_arg, rows_arg) catch |err| {
+ initCore(callbacks, cols_arg, rows_arg) catch |err| {
log.err("init failed: {t}", .{err});
return 2;
};
@@ -302,7 +302,7 @@ export fn pardes_init(runtime: ?*const Callbacks, cols_arg: u16, rows_arg: u16)
/// The shell's gpa in a Debug build, as std.start's is for the others.
var debug_gpa: std.heap.DebugAllocator(.{}) = .init;
-fn initCore(runtime: ?*const Callbacks, cols_arg: u16, rows_arg: u16) !void {
+fn initCore(callbacks: ?*const Callbacks, cols_arg: u16, rows_arg: u16) !void {
// The allocator every other shell gets from std.start: a DebugAllocator
// in Debug, libc's malloc otherwise. libc's measured at least as fast as
// std.heap.smp_allocator everywhere and faster on MuPDF's page-sized
@@ -348,6 +348,7 @@ fn initCore(runtime: ?*const Callbacks, cols_arg: u16, rows_arg: u16) !void {
pardes.syntax.start(allocs.tree_sitter);
errdefer pardes.syntax.stop();
+ opts.tape = pardes.tape.fromEnv();
const core = try pardes.Pardes.init(allocs.pardes, opts);
errdefer core.deinit();
// The workspace tag row is the macOS menu bar's business here (see
@@ -372,7 +373,7 @@ fn initCore(runtime: ?*const Callbacks, cols_arg: u16, rows_arg: u16) !void {
.core = core,
.config_arena = config_arena,
.prompt_rcs = prompt_rcs,
- .runtime = if (runtime) |r| r.* else .{},
+ .callbacks = if (callbacks) |c| c.* else .{},
};
const st = &state.?;
st.inbox = .{ .gpa = gpa, .lsp_allocator = gpa, .io = io, .wake_fn = wakeHost, .wake_ctx = st };
@@ -682,7 +683,7 @@ fn reloadWatchedTheme(st: *State, announce: bool) bool {
live.retries_left = 0;
if (announce) {
var mbuf: [256]u8 = undefined;
- st.core.setMessage(.at(request.pane), message.stamp(&mbuf, "reloaded theme", request.path));
+ st.core.setMessage(request.pane, message.stamp(&mbuf, "reloaded theme", request.path));
}
return true;
}
@@ -1757,14 +1758,14 @@ fn dumpThemes(ctx: ?*anyopaque, id: pardes.Pane.Id) void {
fn setClipboard(ctx: ?*anyopaque, text: []const u8) void {
const st = hostState(ctx);
- const cb = st.runtime.set_clipboard orelse return;
- cb(st.runtime.userdata, text.ptr, text.len);
+ const cb = st.callbacks.set_clipboard orelse return;
+ cb(st.callbacks.userdata, text.ptr, text.len);
}
fn readClipboard(ctx: ?*anyopaque) void {
const st = hostState(ctx);
- const cb = st.runtime.read_clipboard orelse return;
- cb(st.runtime.userdata);
+ const cb = st.callbacks.read_clipboard orelse return;
+ cb(st.callbacks.userdata);
}
fn openLink(_: ?*anyopaque, url: []const u8) void {
@@ -1802,9 +1803,9 @@ fn wakeHost(ctx: ?*anyopaque) void {
}
fn wake(st: *State) void {
- const cb = st.runtime.wakeup orelse return;
+ const cb = st.callbacks.wakeup orelse return;
if (st.wake_pending.swap(true, .acq_rel)) return;
- cb(st.runtime.userdata);
+ cb(st.callbacks.userdata);
}
fn captureEnv(arena: std.mem.Allocator) ?std.process.Environ.Map {
@@ -2057,7 +2058,7 @@ test "mac queued results never cancel a newer LSP request" {
.threaded = undefined,
.io = std.testing.io,
.core = core,
- .runtime = .{},
+ .callbacks = .{},
.config_arena = .init(gpa),
.prompt_rcs = .{},
.inbox = .{ .gpa = gpa, .lsp_allocator = gpa, .io = std.testing.io },
@@ -2100,7 +2101,7 @@ test "mac worker setup failures finish matching LSP and pipe requests" {
.threaded = undefined,
.io = failing_io,
.core = core,
- .runtime = .{},
+ .callbacks = .{},
.config_arena = .init(gpa),
.prompt_rcs = .{},
.inbox = .{ .gpa = failing.allocator(), .lsp_allocator = failing.allocator(), .io = failing_io },
@@ -2111,7 +2112,7 @@ test "mac worker setup failures finish matching LSP and pipe requests" {
const req: host_io.Lsp.Request = .{
.id = core.lsp_ask.wait.?.id,
.kind = .status,
- .pane = @intCast(core.view().active),
+ .pane = .at(core.view().active),
.offset = 0,
.arg = "",
};
@@ -2223,7 +2224,7 @@ test "mac Restore keeps host state and rejects callbacks from the old core" {
.threaded = undefined,
.io = std.testing.io,
.core = core,
- .runtime = .{},
+ .callbacks = .{},
.config_arena = .init(gpa),
.prompt_rcs = .{},
.inbox = .{ .gpa = gpa, .lsp_allocator = gpa, .io = std.testing.io },
@@ -2265,8 +2266,8 @@ test "mac Restore keeps host state and rejects callbacks from the old core" {
.failure = .{ .kind = .exit, .code = 1, .stderr = try gpa.dupe(u8, "old filter failure") },
} });
}
- st.inbox.acceptReader(0, 23);
- _ = st.inbox.pushOutput(0, 23, try gpa.dupe(u8, "old PTY output"));
+ st.inbox.acceptReader(.at(0), 23);
+ _ = st.inbox.pushOutput(.at(0), 23, try gpa.dupe(u8, "old PTY output"));
core.update(.{ .command = try std.fmt.bufPrint(&command, "Restore .zig-cache/tmp/{s}/restore.zon", .{tmp.sub_path}) });
try std.testing.expect(restoreCore(&st));
try std.testing.expect(st.core != core);
@@ -2324,7 +2325,7 @@ test "mac Restore cancels a PTY reader waiting for output capacity" {
.threaded = undefined,
.io = io,
.core = try pardes.Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 }),
- .runtime = .{},
+ .callbacks = .{},
.config_arena = .init(gpa),
.prompt_rcs = .{},
.inbox = .{ .gpa = gpa, .lsp_allocator = gpa, .io = io },
@@ -2336,8 +2337,8 @@ test "mac Restore cancels a PTY reader waiting for output capacity" {
try dump.dumpState(st.core);
try tmp.dir.writeFile(io, .{ .sub_path = "restore.zon", .data = st.core.dump_out.? });
while (st.core.nextEffect()) |_| {}
- st.inbox.acceptReader(1, 1);
- for (0..Inbox.output_capacity) |_| _ = st.inbox.pushOutput(1, 1, try gpa.dupe(u8, "retained output"));
+ st.inbox.acceptReader(.at(1), 1);
+ for (0..Inbox.output_capacity) |_| _ = st.inbox.pushOutput(.at(1), 1, try gpa.dupe(u8, "retained output"));
const child = try host_io.forkShell(null, 0, &st.prompt_rcs, "/bin/sh", "", 12, 40);
st.gens[0] = 1;
st.ptys[0] = .{ .file = child.file, .pid = child.pid, .gen = 1, .reader = .{ .any_future = null, .result = {} } };
@@ -2361,8 +2362,8 @@ test "mac Restore cancels a PTY reader waiting for output capacity" {
try std.testing.expect(st.ptys[0] == null);
try std.testing.expectEqual(@as(usize, 0), st.inbox.len);
try std.testing.expectEqual(@as(u16, 0), st.inbox.space.state.load(.acquire).waiters);
- st.inbox.acceptReader(0, st.gens[0]);
- _ = st.inbox.pushOutput(0, st.gens[0], try gpa.dupe(u8, "fresh output"));
+ st.inbox.acceptReader(.at(0), st.gens[0]);
+ _ = st.inbox.pushOutput(.at(0), st.gens[0], try gpa.dupe(u8, "fresh output"));
var batch = st.inbox.take();
defer for (batch.slice()) |msg| msg.deinit(gpa, gpa);
try std.testing.expectEqual(@as(usize, 1), batch.len);
@@ -2626,7 +2627,7 @@ test "mac row metrics ABI preserves PDF cell dimensions and the unrendered grid"
const gpa = std.testing.allocator;
const core = try pardes.Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
defer core.deinit();
- state = .{ .gpa = gpa, .threaded = undefined, .io = std.testing.io, .core = core, .runtime = .{}, .config_arena = .init(gpa), .prompt_rcs = .{} };
+ state = .{ .gpa = gpa, .threaded = undefined, .io = std.testing.io, .core = core, .callbacks = .{}, .config_arena = .init(gpa), .prompt_rcs = .{} };
defer {
state.?.config_arena.deinit();
state = null;
@@ -2645,7 +2646,7 @@ test "mac tag layer ABI preserves logical capacity and physical grip" {
const gpa = std.testing.allocator;
const core = try pardes.Pardes.init(gpa, .{ .tty_only = true, .cols = 8, .rows = 3 });
defer core.deinit();
- state = .{ .gpa = gpa, .threaded = undefined, .io = std.testing.io, .core = core, .runtime = .{}, .config_arena = .init(gpa), .prompt_rcs = .{} };
+ state = .{ .gpa = gpa, .threaded = undefined, .io = std.testing.io, .core = core, .callbacks = .{}, .config_arena = .init(gpa), .prompt_rcs = .{} };
defer {
for (state.?.tag_cells) |cells| gpa.free(cells);
state.?.config_arena.deinit();