refactor: change a -> allocator

This commit is contained in:
CJ van den Berg 2024-09-02 14:31:49 +02:00
parent ad58b1868d
commit 7b812d73ea
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
63 changed files with 896 additions and 896 deletions

View file

@ -5,7 +5,7 @@ const root = @import("root");
const tracy = @import("tracy"); const tracy = @import("tracy");
const log = @import("log"); const log = @import("log");
a: std.mem.Allocator, allocator: std.mem.Allocator,
pid: tp.pid, pid: tp.pid,
const Self = @This(); const Self = @This();
@ -14,8 +14,8 @@ const sp_tag = "child";
const debug_lsp = true; const debug_lsp = true;
const lsp_request_timeout = std.time.ns_per_s * 30; const lsp_request_timeout = std.time.ns_per_s * 30;
pub fn open(a: std.mem.Allocator, project: []const u8, cmd: tp.message) !Self { pub fn open(allocator: std.mem.Allocator, project: []const u8, cmd: tp.message) !Self {
return .{ .a = a, .pid = try Process.create(a, project, cmd) }; return .{ .allocator = allocator, .pid = try Process.create(allocator, project, cmd) };
} }
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
@ -28,17 +28,17 @@ pub fn term(self: *Self) void {
self.pid.deinit(); self.pid.deinit();
} }
pub fn send_request(self: Self, a: std.mem.Allocator, method: []const u8, m: anytype) !tp.message { pub fn send_request(self: Self, allocator: std.mem.Allocator, method: []const u8, m: anytype) !tp.message {
// const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".send_request" }); // const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".send_request" });
// defer frame.deinit(); // defer frame.deinit();
var cb = std.ArrayList(u8).init(self.a); var cb = std.ArrayList(u8).init(self.allocator);
defer cb.deinit(); defer cb.deinit();
try cbor.writeValue(cb.writer(), m); try cbor.writeValue(cb.writer(), m);
return self.pid.call(a, lsp_request_timeout, .{ "REQ", method, cb.items }); return self.pid.call(allocator, lsp_request_timeout, .{ "REQ", method, cb.items });
} }
pub fn send_notification(self: Self, method: []const u8, m: anytype) !void { pub fn send_notification(self: Self, method: []const u8, m: anytype) !void {
var cb = std.ArrayList(u8).init(self.a); var cb = std.ArrayList(u8).init(self.allocator);
defer cb.deinit(); defer cb.deinit();
try cbor.writeValue(cb.writer(), m); try cbor.writeValue(cb.writer(), m);
return self.send_notification_raw(method, cb.items); return self.send_notification_raw(method, cb.items);
@ -53,7 +53,7 @@ pub fn close(self: *Self) void {
} }
const Process = struct { const Process = struct {
a: std.mem.Allocator, allocator: std.mem.Allocator,
cmd: tp.message, cmd: tp.message,
receiver: Receiver, receiver: Receiver,
sp: ?tp.subprocess = null, sp: ?tp.subprocess = null,
@ -68,7 +68,7 @@ const Process = struct {
const Receiver = tp.Receiver(*Process); const Receiver = tp.Receiver(*Process);
pub fn create(a: std.mem.Allocator, project: []const u8, cmd: tp.message) !tp.pid { pub fn create(allocator: std.mem.Allocator, project: []const u8, cmd: tp.message) !tp.pid {
var tag: []const u8 = undefined; var tag: []const u8 = undefined;
if (try cmd.match(.{tp.extract(&tag)})) { if (try cmd.match(.{tp.extract(&tag)})) {
// //
@ -77,31 +77,31 @@ const Process = struct {
} else { } else {
return tp.exit("no LSP command"); return tp.exit("no LSP command");
} }
const self = try a.create(Process); const self = try allocator.create(Process);
var sp_tag_ = std.ArrayList(u8).init(a); var sp_tag_ = std.ArrayList(u8).init(allocator);
defer sp_tag_.deinit(); defer sp_tag_.deinit();
try sp_tag_.appendSlice(tag); try sp_tag_.appendSlice(tag);
try sp_tag_.appendSlice("-" ++ sp_tag); try sp_tag_.appendSlice("-" ++ sp_tag);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.cmd = try cmd.clone(a), .cmd = try cmd.clone(allocator),
.receiver = Receiver.init(receive, self), .receiver = Receiver.init(receive, self),
.recv_buf = std.ArrayList(u8).init(a), .recv_buf = std.ArrayList(u8).init(allocator),
.parent = tp.self_pid().clone(), .parent = tp.self_pid().clone(),
.tag = try a.dupeZ(u8, tag), .tag = try allocator.dupeZ(u8, tag),
.project = try a.dupeZ(u8, project), .project = try allocator.dupeZ(u8, project),
.requests = std.AutoHashMap(i32, tp.pid).init(a), .requests = std.AutoHashMap(i32, tp.pid).init(allocator),
.sp_tag = try sp_tag_.toOwnedSliceSentinel(0), .sp_tag = try sp_tag_.toOwnedSliceSentinel(0),
}; };
return tp.spawn_link(self.a, self, Process.start, self.tag); return tp.spawn_link(self.allocator, self, Process.start, self.tag);
} }
fn deinit(self: *Process) void { fn deinit(self: *Process) void {
var i = self.requests.iterator(); var i = self.requests.iterator();
while (i.next()) |req| req.value_ptr.deinit(); while (i.next()) |req| req.value_ptr.deinit();
self.a.free(self.sp_tag); self.allocator.free(self.sp_tag);
self.recv_buf.deinit(); self.recv_buf.deinit();
self.a.free(self.cmd.buf); self.allocator.free(self.cmd.buf);
self.close() catch {}; self.close() catch {};
self.write_log("### terminated LSP process ###\n", .{}); self.write_log("### terminated LSP process ###\n", .{});
if (self.log_file) |file| file.close(); if (self.log_file) |file| file.close();
@ -127,10 +127,10 @@ const Process = struct {
const frame = tracy.initZone(@src(), .{ .name = module_name ++ " start" }); const frame = tracy.initZone(@src(), .{ .name = module_name ++ " start" });
defer frame.deinit(); defer frame.deinit();
_ = tp.set_trap(true); _ = tp.set_trap(true);
self.sp = tp.subprocess.init(self.a, self.cmd, self.sp_tag, .Pipe) catch |e| return tp.exit_error(e, @errorReturnTrace()); self.sp = tp.subprocess.init(self.allocator, self.cmd, self.sp_tag, .Pipe) catch |e| return tp.exit_error(e, @errorReturnTrace());
tp.receive(&self.receiver); tp.receive(&self.receiver);
var log_file_path = std.ArrayList(u8).init(self.a); var log_file_path = std.ArrayList(u8).init(self.allocator);
defer log_file_path.deinit(); defer log_file_path.deinit();
const state_dir = root.get_state_dir() catch |e| return tp.exit_error(e, @errorReturnTrace()); const state_dir = root.get_state_dir() catch |e| return tp.exit_error(e, @errorReturnTrace());
log_file_path.writer().print("{s}/lsp-{s}.log", .{ state_dir, self.tag }) catch |e| return tp.exit_error(e, @errorReturnTrace()); log_file_path.writer().print("{s}/lsp-{s}.log", .{ state_dir, self.tag }) catch |e| return tp.exit_error(e, @errorReturnTrace());
@ -248,7 +248,7 @@ const Process = struct {
const id = self.next_id; const id = self.next_id;
self.next_id += 1; self.next_id += 1;
var msg = std.ArrayList(u8).init(self.a); var msg = std.ArrayList(u8).init(self.allocator);
defer msg.deinit(); defer msg.deinit();
const msg_writer = msg.writer(); const msg_writer = msg.writer();
try cbor.writeMapHeader(msg_writer, 4); try cbor.writeMapHeader(msg_writer, 4);
@ -261,9 +261,9 @@ const Process = struct {
try cbor.writeValue(msg_writer, "params"); try cbor.writeValue(msg_writer, "params");
_ = try msg_writer.write(params_cb); _ = try msg_writer.write(params_cb);
const json = try cbor.toJsonAlloc(self.a, msg.items); const json = try cbor.toJsonAlloc(self.allocator, msg.items);
defer self.a.free(json); defer self.allocator.free(json);
var output = std.ArrayList(u8).init(self.a); var output = std.ArrayList(u8).init(self.allocator);
defer output.deinit(); defer output.deinit();
const writer = output.writer(); const writer = output.writer();
const terminator = "\r\n"; const terminator = "\r\n";
@ -282,7 +282,7 @@ const Process = struct {
const have_params = !(cbor.match(params_cb, cbor.null_) catch false); const have_params = !(cbor.match(params_cb, cbor.null_) catch false);
var msg = std.ArrayList(u8).init(self.a); var msg = std.ArrayList(u8).init(self.allocator);
defer msg.deinit(); defer msg.deinit();
const msg_writer = msg.writer(); const msg_writer = msg.writer();
try cbor.writeMapHeader(msg_writer, 3); try cbor.writeMapHeader(msg_writer, 3);
@ -297,9 +297,9 @@ const Process = struct {
try cbor.writeMapHeader(msg_writer, 0); try cbor.writeMapHeader(msg_writer, 0);
} }
const json = try cbor.toJsonAlloc(self.a, msg.items); const json = try cbor.toJsonAlloc(self.allocator, msg.items);
defer self.a.free(json); defer self.allocator.free(json);
var output = std.ArrayList(u8).init(self.a); var output = std.ArrayList(u8).init(self.allocator);
defer output.deinit(); defer output.deinit();
const writer = output.writer(); const writer = output.writer();
const terminator = "\r\n"; const terminator = "\r\n";
@ -321,20 +321,20 @@ const Process = struct {
const buf = try self.recv_buf.toOwnedSlice(); const buf = try self.recv_buf.toOwnedSlice();
const data = buf[headers_end + sep.len .. headers_end + sep.len + headers.content_length]; const data = buf[headers_end + sep.len .. headers_end + sep.len + headers.content_length];
const rest = buf[headers_end + sep.len + headers.content_length ..]; const rest = buf[headers_end + sep.len + headers.content_length ..];
defer self.a.free(buf); defer self.allocator.free(buf);
if (rest.len > 0) try self.recv_buf.appendSlice(rest); if (rest.len > 0) try self.recv_buf.appendSlice(rest);
const message = .{ .body = data[0..headers.content_length] }; const message = .{ .body = data[0..headers.content_length] };
const cb = try cbor.fromJsonAlloc(self.a, message.body); const cb = try cbor.fromJsonAlloc(self.allocator, message.body);
defer self.a.free(cb); defer self.allocator.free(cb);
try self.receive_lsp_message(cb); try self.receive_lsp_message(cb);
if (rest.len > 0) return self.frame_message_recv(); if (rest.len > 0) return self.frame_message_recv();
} }
fn receive_lsp_request(self: *Process, id: i32, method: []const u8, params: ?[]const u8) !void { fn receive_lsp_request(self: *Process, id: i32, method: []const u8, params: ?[]const u8) !void {
const json = if (params) |p| try cbor.toJsonPrettyAlloc(self.a, p) else null; const json = if (params) |p| try cbor.toJsonPrettyAlloc(self.allocator, p) else null;
defer if (json) |p| self.a.free(p); defer if (json) |p| self.allocator.free(p);
self.write_log("### RECV req: {d}\nmethod: {s}\n{s}\n###\n", .{ id, method, json orelse "no params" }); self.write_log("### RECV req: {d}\nmethod: {s}\n{s}\n###\n", .{ id, method, json orelse "no params" });
var msg = std.ArrayList(u8).init(self.a); var msg = std.ArrayList(u8).init(self.allocator);
defer msg.deinit(); defer msg.deinit();
const writer = msg.writer(); const writer = msg.writer();
try cbor.writeArrayHeader(writer, 7); try cbor.writeArrayHeader(writer, 7);
@ -349,13 +349,13 @@ const Process = struct {
} }
fn receive_lsp_response(self: *Process, id: i32, result: ?[]const u8, err: ?[]const u8) !void { fn receive_lsp_response(self: *Process, id: i32, result: ?[]const u8, err: ?[]const u8) !void {
const json = if (result) |p| try cbor.toJsonPrettyAlloc(self.a, p) else null; const json = if (result) |p| try cbor.toJsonPrettyAlloc(self.allocator, p) else null;
defer if (json) |p| self.a.free(p); defer if (json) |p| self.allocator.free(p);
const json_err = if (err) |p| try cbor.toJsonPrettyAlloc(self.a, p) else null; const json_err = if (err) |p| try cbor.toJsonPrettyAlloc(self.allocator, p) else null;
defer if (json_err) |p| self.a.free(p); defer if (json_err) |p| self.allocator.free(p);
self.write_log("### RECV rsp: {d} {s}\n{s}\n###\n", .{ id, if (json_err) |_| "error" else "response", json_err orelse json orelse "no result" }); self.write_log("### RECV rsp: {d} {s}\n{s}\n###\n", .{ id, if (json_err) |_| "error" else "response", json_err orelse json orelse "no result" });
const from = self.requests.get(id) orelse return; const from = self.requests.get(id) orelse return;
var msg = std.ArrayList(u8).init(self.a); var msg = std.ArrayList(u8).init(self.allocator);
defer msg.deinit(); defer msg.deinit();
const writer = msg.writer(); const writer = msg.writer();
try cbor.writeArrayHeader(writer, 4); try cbor.writeArrayHeader(writer, 4);
@ -372,10 +372,10 @@ const Process = struct {
} }
fn receive_lsp_notification(self: *Process, method: []const u8, params: ?[]const u8) !void { fn receive_lsp_notification(self: *Process, method: []const u8, params: ?[]const u8) !void {
const json = if (params) |p| try cbor.toJsonPrettyAlloc(self.a, p) else null; const json = if (params) |p| try cbor.toJsonPrettyAlloc(self.allocator, p) else null;
defer if (json) |p| self.a.free(p); defer if (json) |p| self.allocator.free(p);
self.write_log("### RECV notify:\nmethod: {s}\n{s}\n###\n", .{ method, json orelse "no params" }); self.write_log("### RECV notify:\nmethod: {s}\n{s}\n###\n", .{ method, json orelse "no params" });
var msg = std.ArrayList(u8).init(self.a); var msg = std.ArrayList(u8).init(self.allocator);
defer msg.deinit(); defer msg.deinit();
const writer = msg.writer(); const writer = msg.writer();
try cbor.writeArrayHeader(writer, 6); try cbor.writeArrayHeader(writer, 6);

View file

@ -10,7 +10,7 @@ const builtin = @import("builtin");
const LSP = @import("LSP.zig"); const LSP = @import("LSP.zig");
a: std.mem.Allocator, allocator: std.mem.Allocator,
name: []const u8, name: []const u8,
files: std.ArrayList(File), files: std.ArrayList(File),
pending: std.ArrayList(File), pending: std.ArrayList(File),
@ -29,31 +29,31 @@ const File = struct {
visited: bool = false, visited: bool = false,
}; };
pub fn init(a: std.mem.Allocator, name: []const u8) error{OutOfMemory}!Self { pub fn init(allocator: std.mem.Allocator, name: []const u8) error{OutOfMemory}!Self {
return .{ return .{
.a = a, .allocator = allocator,
.name = try a.dupe(u8, name), .name = try allocator.dupe(u8, name),
.files = std.ArrayList(File).init(a), .files = std.ArrayList(File).init(allocator),
.pending = std.ArrayList(File).init(a), .pending = std.ArrayList(File).init(allocator),
.open_time = std.time.milliTimestamp(), .open_time = std.time.milliTimestamp(),
.language_servers = std.StringHashMap(LSP).init(a), .language_servers = std.StringHashMap(LSP).init(allocator),
.file_language_server = std.StringHashMap(LSP).init(a), .file_language_server = std.StringHashMap(LSP).init(allocator),
}; };
} }
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
var i_ = self.file_language_server.iterator(); var i_ = self.file_language_server.iterator();
while (i_.next()) |p| { while (i_.next()) |p| {
self.a.free(p.key_ptr.*); self.allocator.free(p.key_ptr.*);
} }
var i = self.language_servers.iterator(); var i = self.language_servers.iterator();
while (i.next()) |p| { while (i.next()) |p| {
self.a.free(p.key_ptr.*); self.allocator.free(p.key_ptr.*);
p.value_ptr.*.term(); p.value_ptr.*.term();
} }
for (self.files.items) |file| self.a.free(file.path); for (self.files.items) |file| self.allocator.free(file.path);
self.files.deinit(); self.files.deinit();
self.a.free(self.name); self.allocator.free(self.name);
} }
pub fn write_state(self: *Self, writer: anytype) !void { pub fn write_state(self: *Self, writer: anytype) !void {
@ -100,14 +100,14 @@ fn get_lsp(self: *Self, language_server: []const u8) !LSP {
if (self.language_servers.get(language_server)) |lsp| return lsp; if (self.language_servers.get(language_server)) |lsp| return lsp;
const logger = log.logger("lsp"); const logger = log.logger("lsp");
errdefer |e| logger.print_err("get_lsp", "failed to initialize LSP: {s} -> {any}", .{ fmt_lsp_name_func(language_server), e }); errdefer |e| logger.print_err("get_lsp", "failed to initialize LSP: {s} -> {any}", .{ fmt_lsp_name_func(language_server), e });
const lsp = try LSP.open(self.a, self.name, .{ .buf = language_server }); const lsp = try LSP.open(self.allocator, self.name, .{ .buf = language_server });
try self.language_servers.put(try self.a.dupe(u8, language_server), lsp); try self.language_servers.put(try self.allocator.dupe(u8, language_server), lsp);
const uri = try self.make_URI(null); const uri = try self.make_URI(null);
defer self.a.free(uri); defer self.allocator.free(uri);
const basename_begin = std.mem.lastIndexOfScalar(u8, self.name, std.fs.path.sep); const basename_begin = std.mem.lastIndexOfScalar(u8, self.name, std.fs.path.sep);
const basename = if (basename_begin) |begin| self.name[begin + 1 ..] else self.name; const basename = if (basename_begin) |begin| self.name[begin + 1 ..] else self.name;
const response = try self.send_lsp_init_request(lsp, self.name, basename, uri); const response = try self.send_lsp_init_request(lsp, self.name, basename, uri);
defer self.a.free(response.buf); defer self.allocator.free(response.buf);
try lsp.send_notification("initialized", .{}); try lsp.send_notification("initialized", .{});
logger.print("initialized LSP: {s}", .{fmt_lsp_name_func(language_server)}); logger.print("initialized LSP: {s}", .{fmt_lsp_name_func(language_server)});
return lsp; return lsp;
@ -125,7 +125,7 @@ fn get_file_lsp(self: *Self, file_path: []const u8) !LSP {
} }
fn make_URI(self: *Self, file_path: ?[]const u8) ![]const u8 { fn make_URI(self: *Self, file_path: ?[]const u8) ![]const u8 {
var buf = std.ArrayList(u8).init(self.a); var buf = std.ArrayList(u8).init(self.allocator);
if (file_path) |path| { if (file_path) |path| {
if (std.fs.path.isAbsolute(path)) { if (std.fs.path.isAbsolute(path)) {
try buf.writer().print("file://{s}", .{path}); try buf.writer().print("file://{s}", .{path});
@ -164,8 +164,8 @@ fn simple_query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: [
for (self.files.items) |file| { for (self.files.items) |file| {
if (file.path.len < query.len) continue; if (file.path.len < query.len) continue;
if (std.mem.indexOf(u8, file.path, query)) |idx| { if (std.mem.indexOf(u8, file.path, query)) |idx| {
var matches = try self.a.alloc(usize, query.len); var matches = try self.allocator.alloc(usize, query.len);
defer self.a.free(matches); defer self.allocator.free(matches);
var n: usize = 0; var n: usize = 0;
while (n < query.len) : (n += 1) matches[n] = idx + n; while (n < query.len) : (n += 1) matches[n] = idx + n;
try from.send(.{ "PRJ", "recent", self.longest_file_path, file.path, matches }); try from.send(.{ "PRJ", "recent", self.longest_file_path, file.path, matches });
@ -182,7 +182,7 @@ pub fn query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: []co
defer from.send(.{ "PRJ", "recent_done", self.longest_file_path, query }) catch {}; defer from.send(.{ "PRJ", "recent_done", self.longest_file_path, query }) catch {};
var searcher = try fuzzig.Ascii.init( var searcher = try fuzzig.Ascii.init(
self.a, self.allocator,
4096, // haystack max size 4096, // haystack max size
4096, // needle max size 4096, // needle max size
.{ .case_sensitive = false }, .{ .case_sensitive = false },
@ -194,7 +194,7 @@ pub fn query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: []co
score: i32, score: i32,
matches: []const usize, matches: []const usize,
}; };
var matches = std.ArrayList(Match).init(self.a); var matches = std.ArrayList(Match).init(self.allocator);
for (self.files.items) |file| { for (self.files.items) |file| {
const match = searcher.scoreMatches(file.path, query); const match = searcher.scoreMatches(file.path, query);
@ -202,7 +202,7 @@ pub fn query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: []co
(try matches.addOne()).* = .{ (try matches.addOne()).* = .{
.path = file.path, .path = file.path,
.score = score, .score = score,
.matches = try self.a.dupe(usize, match.matches), .matches = try self.allocator.dupe(usize, match.matches),
}; };
} }
} }
@ -222,19 +222,19 @@ pub fn query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: []co
pub fn add_pending_file(self: *Self, file_path: []const u8, mtime: i128) error{OutOfMemory}!void { pub fn add_pending_file(self: *Self, file_path: []const u8, mtime: i128) error{OutOfMemory}!void {
self.longest_file_path = @max(self.longest_file_path, file_path.len); self.longest_file_path = @max(self.longest_file_path, file_path.len);
(try self.pending.addOne()).* = .{ .path = try self.a.dupe(u8, file_path), .mtime = mtime }; (try self.pending.addOne()).* = .{ .path = try self.allocator.dupe(u8, file_path), .mtime = mtime };
} }
pub fn merge_pending_files(self: *Self) error{OutOfMemory}!void { pub fn merge_pending_files(self: *Self) error{OutOfMemory}!void {
defer self.sort_files_by_mtime(); defer self.sort_files_by_mtime();
const existing = try self.files.toOwnedSlice(); const existing = try self.files.toOwnedSlice();
self.files = self.pending; self.files = self.pending;
self.pending = std.ArrayList(File).init(self.a); self.pending = std.ArrayList(File).init(self.allocator);
for (existing) |*file| { for (existing) |*file| {
self.update_mru_internal(file.path, file.mtime, file.row, file.col) catch {}; self.update_mru_internal(file.path, file.mtime, file.row, file.col) catch {};
self.a.free(file.path); self.allocator.free(file.path);
} }
self.a.free(existing); self.allocator.free(existing);
} }
pub fn update_mru(self: *Self, file_path: []const u8, row: usize, col: usize) !void { pub fn update_mru(self: *Self, file_path: []const u8, row: usize, col: usize) !void {
@ -255,7 +255,7 @@ fn update_mru_internal(self: *Self, file_path: []const u8, mtime: i128, row: usi
} }
if (row != 0) { if (row != 0) {
(try self.files.addOne()).* = .{ (try self.files.addOne()).* = .{
.path = try self.a.dupe(u8, file_path), .path = try self.allocator.dupe(u8, file_path),
.mtime = mtime, .mtime = mtime,
.row = row, .row = row,
.col = col, .col = col,
@ -263,7 +263,7 @@ fn update_mru_internal(self: *Self, file_path: []const u8, mtime: i128, row: usi
}; };
} else { } else {
(try self.files.addOne()).* = .{ (try self.files.addOne()).* = .{
.path = try self.a.dupe(u8, file_path), .path = try self.allocator.dupe(u8, file_path),
.mtime = mtime, .mtime = mtime,
}; };
} }
@ -282,11 +282,11 @@ pub fn did_open(self: *Self, file_path: []const u8, file_type: []const u8, langu
self.update_mru(file_path, 0, 0) catch {}; self.update_mru(file_path, 0, 0) catch {};
const lsp = try self.get_lsp(language_server); const lsp = try self.get_lsp(language_server);
if (!self.file_language_server.contains(file_path)) { if (!self.file_language_server.contains(file_path)) {
const key = try self.a.dupe(u8, file_path); const key = try self.allocator.dupe(u8, file_path);
try self.file_language_server.put(key, lsp); try self.file_language_server.put(key, lsp);
} }
const uri = try self.make_URI(file_path); const uri = try self.make_URI(file_path);
defer self.a.free(uri); defer self.allocator.free(uri);
try lsp.send_notification("textDocument/didOpen", .{ try lsp.send_notification("textDocument/didOpen", .{
.textDocument = .{ .uri = uri, .languageId = file_type, .version = version, .text = text }, .textDocument = .{ .uri = uri, .languageId = file_type, .version = version, .text = text },
}); });
@ -295,34 +295,34 @@ pub fn did_open(self: *Self, file_path: []const u8, file_type: []const u8, langu
pub fn did_change(self: *Self, file_path: []const u8, version: usize, root_dst_addr: usize, root_src_addr: usize) !void { pub fn did_change(self: *Self, file_path: []const u8, version: usize, root_dst_addr: usize, root_src_addr: usize) !void {
const lsp = try self.get_file_lsp(file_path); const lsp = try self.get_file_lsp(file_path);
const uri = try self.make_URI(file_path); const uri = try self.make_URI(file_path);
defer self.a.free(uri); defer self.allocator.free(uri);
const root_dst: Buffer.Root = if (root_dst_addr == 0) return else @ptrFromInt(root_dst_addr); const root_dst: Buffer.Root = if (root_dst_addr == 0) return else @ptrFromInt(root_dst_addr);
const root_src: Buffer.Root = if (root_src_addr == 0) return else @ptrFromInt(root_src_addr); const root_src: Buffer.Root = if (root_src_addr == 0) return else @ptrFromInt(root_src_addr);
var dizzy_edits = std.ArrayListUnmanaged(dizzy.Edit){}; var dizzy_edits = std.ArrayListUnmanaged(dizzy.Edit){};
var dst = std.ArrayList(u8).init(self.a); var dst = std.ArrayList(u8).init(self.allocator);
var src = std.ArrayList(u8).init(self.a); var src = std.ArrayList(u8).init(self.allocator);
var scratch = std.ArrayListUnmanaged(u32){}; var scratch = std.ArrayListUnmanaged(u32){};
var edits_cb = std.ArrayList(u8).init(self.a); var edits_cb = std.ArrayList(u8).init(self.allocator);
const writer = edits_cb.writer(); const writer = edits_cb.writer();
defer { defer {
edits_cb.deinit(); edits_cb.deinit();
dst.deinit(); dst.deinit();
src.deinit(); src.deinit();
scratch.deinit(self.a); scratch.deinit(self.allocator);
dizzy_edits.deinit(self.a); dizzy_edits.deinit(self.allocator);
} }
try root_dst.store(dst.writer()); try root_dst.store(dst.writer());
try root_src.store(src.writer()); try root_src.store(src.writer());
const scratch_len = 4 * (dst.items.len + src.items.len) + 2; const scratch_len = 4 * (dst.items.len + src.items.len) + 2;
try scratch.ensureTotalCapacity(self.a, scratch_len); try scratch.ensureTotalCapacity(self.allocator, scratch_len);
scratch.items.len = scratch_len; scratch.items.len = scratch_len;
try dizzy.PrimitiveSliceDiffer(u8).diff(self.a, &dizzy_edits, src.items, dst.items, scratch.items); try dizzy.PrimitiveSliceDiffer(u8).diff(self.allocator, &dizzy_edits, src.items, dst.items, scratch.items);
var lines_dst: usize = 0; var lines_dst: usize = 0;
var last_offset: usize = 0; var last_offset: usize = 0;
@ -361,7 +361,7 @@ pub fn did_change(self: *Self, file_path: []const u8, version: usize, root_dst_a
} }
} }
var msg = std.ArrayList(u8).init(self.a); var msg = std.ArrayList(u8).init(self.allocator);
defer msg.deinit(); defer msg.deinit();
const msg_writer = msg.writer(); const msg_writer = msg.writer();
try cbor.writeMapHeader(msg_writer, 2); try cbor.writeMapHeader(msg_writer, 2);
@ -389,7 +389,7 @@ fn scan_char(chars: []const u8, lines: *usize, char: u8, last_offset: ?*usize) v
pub fn did_save(self: *Self, file_path: []const u8) !void { pub fn did_save(self: *Self, file_path: []const u8) !void {
const lsp = try self.get_file_lsp(file_path); const lsp = try self.get_file_lsp(file_path);
const uri = try self.make_URI(file_path); const uri = try self.make_URI(file_path);
defer self.a.free(uri); defer self.allocator.free(uri);
try lsp.send_notification("textDocument/didSave", .{ try lsp.send_notification("textDocument/didSave", .{
.textDocument = .{ .uri = uri }, .textDocument = .{ .uri = uri },
}); });
@ -398,7 +398,7 @@ pub fn did_save(self: *Self, file_path: []const u8) !void {
pub fn did_close(self: *Self, file_path: []const u8) !void { pub fn did_close(self: *Self, file_path: []const u8) !void {
const lsp = try self.get_file_lsp(file_path); const lsp = try self.get_file_lsp(file_path);
const uri = try self.make_URI(file_path); const uri = try self.make_URI(file_path);
defer self.a.free(uri); defer self.allocator.free(uri);
try lsp.send_notification("textDocument/didClose", .{ try lsp.send_notification("textDocument/didClose", .{
.textDocument = .{ .uri = uri }, .textDocument = .{ .uri = uri },
}); });
@ -423,12 +423,12 @@ pub fn goto_type_definition(self: *Self, from: tp.pid_ref, file_path: []const u8
fn send_goto_request(self: *Self, from: tp.pid_ref, file_path: []const u8, row: usize, col: usize, method: []const u8) !void { fn send_goto_request(self: *Self, from: tp.pid_ref, file_path: []const u8, row: usize, col: usize, method: []const u8) !void {
const lsp = try self.get_file_lsp(file_path); const lsp = try self.get_file_lsp(file_path);
const uri = try self.make_URI(file_path); const uri = try self.make_URI(file_path);
defer self.a.free(uri); defer self.allocator.free(uri);
const response = try lsp.send_request(self.a, method, .{ const response = try lsp.send_request(self.allocator, method, .{
.textDocument = .{ .uri = uri }, .textDocument = .{ .uri = uri },
.position = .{ .line = row, .character = col }, .position = .{ .line = row, .character = col },
}); });
defer self.a.free(response.buf); defer self.allocator.free(response.buf);
var link: []const u8 = undefined; var link: []const u8 = undefined;
var locations: []const u8 = undefined; var locations: []const u8 = undefined;
if (try response.match(.{ "child", tp.string, "result", tp.array })) { if (try response.match(.{ "child", tp.string, "result", tp.array })) {
@ -505,15 +505,15 @@ fn navigate_to_location_link(_: *Self, from: tp.pid_ref, location_link: []const
pub fn references(self: *Self, from: tp.pid_ref, file_path: []const u8, row: usize, col: usize) !void { pub fn references(self: *Self, from: tp.pid_ref, file_path: []const u8, row: usize, col: usize) !void {
const lsp = try self.get_file_lsp(file_path); const lsp = try self.get_file_lsp(file_path);
const uri = try self.make_URI(file_path); const uri = try self.make_URI(file_path);
defer self.a.free(uri); defer self.allocator.free(uri);
log.logger("lsp").print("finding references...", .{}); log.logger("lsp").print("finding references...", .{});
const response = try lsp.send_request(self.a, "textDocument/references", .{ const response = try lsp.send_request(self.allocator, "textDocument/references", .{
.textDocument = .{ .uri = uri }, .textDocument = .{ .uri = uri },
.position = .{ .line = row, .character = col }, .position = .{ .line = row, .character = col },
.context = .{ .includeDeclaration = true }, .context = .{ .includeDeclaration = true },
}); });
defer self.a.free(response.buf); defer self.allocator.free(response.buf);
var locations: []const u8 = undefined; var locations: []const u8 = undefined;
if (try response.match(.{ "child", tp.string, "result", tp.null_ })) { if (try response.match(.{ "child", tp.string, "result", tp.null_ })) {
return; return;
@ -571,8 +571,8 @@ fn send_reference(self: *Self, to: tp.pid_ref, location: []const u8) !void {
file_path[i] = '\\'; file_path[i] = '\\';
}; };
} }
const line = try self.get_line_of_file(self.a, file_path, targetRange.?.start.line); const line = try self.get_line_of_file(self.allocator, file_path, targetRange.?.start.line);
defer self.a.free(line); defer self.allocator.free(line);
const file_path_ = if (file_path.len > self.name.len and std.mem.eql(u8, self.name, file_path[0..self.name.len])) const file_path_ = if (file_path.len > self.name.len and std.mem.eql(u8, self.name, file_path[0..self.name.len]))
file_path[self.name.len + 1 ..] file_path[self.name.len + 1 ..]
else else
@ -591,12 +591,12 @@ fn send_reference(self: *Self, to: tp.pid_ref, location: []const u8) !void {
pub fn completion(self: *Self, _: tp.pid_ref, file_path: []const u8, row: usize, col: usize) !void { pub fn completion(self: *Self, _: tp.pid_ref, file_path: []const u8, row: usize, col: usize) !void {
const lsp = try self.get_file_lsp(file_path); const lsp = try self.get_file_lsp(file_path);
const uri = try self.make_URI(file_path); const uri = try self.make_URI(file_path);
defer self.a.free(uri); defer self.allocator.free(uri);
const response = try lsp.send_request(self.a, "textDocument/completion", .{ const response = try lsp.send_request(self.allocator, "textDocument/completion", .{
.textDocument = .{ .uri = uri }, .textDocument = .{ .uri = uri },
.position = .{ .line = row, .character = col }, .position = .{ .line = row, .character = col },
}); });
defer self.a.free(response.buf); defer self.allocator.free(response.buf);
} }
pub fn publish_diagnostics(self: *Self, to: tp.pid_ref, params_cb: []const u8) !void { pub fn publish_diagnostics(self: *Self, to: tp.pid_ref, params_cb: []const u8) !void {
@ -750,7 +750,7 @@ pub fn show_message(_: *Self, _: tp.pid_ref, params_cb: []const u8) !void {
} }
fn send_lsp_init_request(self: *Self, lsp: LSP, project_path: []const u8, project_basename: []const u8, project_uri: []const u8) !tp.message { fn send_lsp_init_request(self: *Self, lsp: LSP, project_path: []const u8, project_basename: []const u8, project_uri: []const u8) !tp.message {
return lsp.send_request(self.a, "initialize", .{ return lsp.send_request(self.allocator, "initialize", .{
.processId = if (builtin.os.tag == .linux) std.os.linux.getpid() else null, .processId = if (builtin.os.tag == .linux) std.os.linux.getpid() else null,
.rootPath = project_path, .rootPath = project_path,
.rootUri = project_uri, .rootUri = project_uri,
@ -1075,13 +1075,13 @@ fn format_lsp_name_func(
const eol = '\n'; const eol = '\n';
fn get_line_of_file(self: *Self, a: std.mem.Allocator, file_path: []const u8, line_: usize) ![]const u8 { fn get_line_of_file(self: *Self, allocator: std.mem.Allocator, file_path: []const u8, line_: usize) ![]const u8 {
const line = line_ + 1; const line = line_ + 1;
const file = try std.fs.cwd().openFile(file_path, .{ .mode = .read_only }); const file = try std.fs.cwd().openFile(file_path, .{ .mode = .read_only });
defer file.close(); defer file.close();
const stat = try file.stat(); const stat = try file.stat();
var buf = try a.alloc(u8, @intCast(stat.size)); var buf = try allocator.alloc(u8, @intCast(stat.size));
defer a.free(buf); defer allocator.free(buf);
const read_size = try file.reader().readAll(buf); const read_size = try file.reader().readAll(buf);
if (read_size != @as(@TypeOf(read_size), @intCast(stat.size))) if (read_size != @as(@TypeOf(read_size), @intCast(stat.size)))
@panic("get_line_of_file: buffer underrun"); @panic("get_line_of_file: buffer underrun");
@ -1089,15 +1089,15 @@ fn get_line_of_file(self: *Self, a: std.mem.Allocator, file_path: []const u8, li
var line_count: usize = 1; var line_count: usize = 1;
for (0..buf.len) |i| { for (0..buf.len) |i| {
if (line_count == line) if (line_count == line)
return self.get_line(a, buf[i..]); return self.get_line(allocator, buf[i..]);
if (buf[i] == eol) line_count += 1; if (buf[i] == eol) line_count += 1;
} }
return a.dupe(u8, ""); return allocator.dupe(u8, "");
} }
pub fn get_line(_: *Self, a: std.mem.Allocator, buf: []const u8) ![]const u8 { pub fn get_line(_: *Self, allocator: std.mem.Allocator, buf: []const u8) ![]const u8 {
for (0..buf.len) |i| { for (0..buf.len) |i| {
if (buf[i] == eol) return a.dupe(u8, buf[0..i]); if (buf[i] == eol) return allocator.dupe(u8, buf[0..i]);
} }
return a.dupe(u8, buf); return allocator.dupe(u8, buf);
} }

View file

@ -25,8 +25,8 @@ pub const Metrics = struct {
}; };
arena: std.heap.ArenaAllocator, arena: std.heap.ArenaAllocator,
a: Allocator, allocator: Allocator,
external_a: Allocator, external_allocator: Allocator,
root: Root, root: Root,
leaves_buf: ?[]Node = null, leaves_buf: ?[]Node = null,
file_buf: ?[]const u8 = null, file_buf: ?[]const u8 = null,
@ -111,7 +111,7 @@ pub const Branch = struct {
return result; return result;
} }
fn merge_results(self: *const Branch, a: Allocator, left: WalkerMut, right: WalkerMut) WalkerMut { fn merge_results(self: *const Branch, allocator: Allocator, left: WalkerMut, right: WalkerMut) WalkerMut {
var result = WalkerMut{}; var result = WalkerMut{};
result.err = if (left.err) |_| left.err else right.err; result.err = if (left.err) |_| left.err else right.err;
if (left.replace != null or right.replace != null) { if (left.replace != null or right.replace != null) {
@ -122,7 +122,7 @@ pub const Branch = struct {
else if (new_right.is_empty()) else if (new_right.is_empty())
new_left new_left
else else
Node.new(a, new_left, new_right) catch |e| return .{ .err = e }; Node.new(allocator, new_left, new_right) catch |e| return .{ .err = e };
} }
result.keep_walking = left.keep_walking and right.keep_walking; result.keep_walking = left.keep_walking and right.keep_walking;
result.found = left.found or right.found; result.found = left.found or right.found;
@ -135,10 +135,10 @@ pub const Leaf = struct {
bol: bool = true, bol: bool = true,
eol: bool = true, eol: bool = true,
fn new(a: Allocator, piece: []const u8, bol: bool, eol: bool) !*const Node { fn new(allocator: Allocator, piece: []const u8, bol: bool, eol: bool) !*const Node {
if (piece.len == 0) if (piece.len == 0)
return if (!bol and !eol) &empty_leaf else if (bol and !eol) &empty_bol_leaf else if (!bol and eol) &empty_eol_leaf else &empty_line_leaf; return if (!bol and !eol) &empty_leaf else if (bol and !eol) &empty_bol_leaf else if (!bol and eol) &empty_eol_leaf else &empty_line_leaf;
const node = try a.create(Node); const node = try allocator.create(Node);
node.* = .{ .leaf = .{ .buf = piece, .bol = bol, .eol = eol } }; node.* = .{ .leaf = .{ .buf = piece, .bol = bol, .eol = eol } };
return node; return node;
} }
@ -242,8 +242,8 @@ const Node = union(enum) {
const walker = *const fn (ctx: *anyopaque, node: *const Node) WalkerMut; const walker = *const fn (ctx: *anyopaque, node: *const Node) WalkerMut;
fn new(a: Allocator, l: *const Node, r: *const Node) !*const Node { fn new(allocator: Allocator, l: *const Node, r: *const Node) !*const Node {
const node = try a.create(Node); const node = try allocator.create(Node);
const l_weights_sum = l.weights_sum(); const l_weights_sum = l.weights_sum();
var weights_sum_ = Weights{}; var weights_sum_ = Weights{};
weights_sum_.add(l_weights_sum); weights_sum_.add(l_weights_sum);
@ -279,24 +279,24 @@ const Node = union(enum) {
}; };
} }
pub fn rebalance(self: *const Node, a: Allocator, tmp_a: Allocator) !Root { pub fn rebalance(self: *const Node, allocator: Allocator, tmp_allocator: Allocator) !Root {
return if (self.is_balanced()) self else bal: { return if (self.is_balanced()) self else bal: {
const leaves = try self.collect_leaves(tmp_a); const leaves = try self.collect_leaves(tmp_allocator);
defer tmp_a.free(leaves); defer tmp_allocator.free(leaves);
break :bal self.merge(leaves, a); break :bal self.merge(leaves, allocator);
}; };
} }
fn merge(self: *const Node, leaves: []*const Node, a: Allocator) !Root { fn merge(self: *const Node, leaves: []*const Node, allocator: Allocator) !Root {
const len = leaves.len; const len = leaves.len;
if (len == 1) { if (len == 1) {
return leaves[0]; return leaves[0];
} }
if (len == 2) { if (len == 2) {
return Node.new(a, leaves[0], leaves[1]); return Node.new(allocator, leaves[0], leaves[1]);
} }
const mid = len / 2; const mid = len / 2;
return Node.new(a, try self.merge(leaves[0..mid], a), try self.merge(leaves[mid..], a)); return Node.new(allocator, try self.merge(leaves[0..mid], allocator), try self.merge(leaves[mid..], allocator));
} }
fn is_empty(self: *const Node) bool { fn is_empty(self: *const Node) bool {
@ -316,8 +316,8 @@ const Node = union(enum) {
} }
} }
fn collect_leaves(self: *const Node, a: Allocator) ![]*const Node { fn collect_leaves(self: *const Node, allocator: Allocator) ![]*const Node {
var leaves = ArrayList(*const Node).init(a); var leaves = ArrayList(*const Node).init(allocator);
try leaves.ensureTotalCapacity(self.lines()); try leaves.ensureTotalCapacity(self.lines());
try self.collect(&leaves); try self.collect(&leaves);
return leaves.toOwnedSlice(); return leaves.toOwnedSlice();
@ -340,21 +340,21 @@ const Node = union(enum) {
} }
} }
fn walk(self: *const Node, a: Allocator, f: WalkerMut.F, ctx: *anyopaque, metrics: Metrics) WalkerMut { fn walk(self: *const Node, allocator: Allocator, f: WalkerMut.F, ctx: *anyopaque, metrics: Metrics) WalkerMut {
switch (self.*) { switch (self.*) {
.node => |*node| { .node => |*node| {
const left = node.left.walk(a, f, ctx, metrics); const left = node.left.walk(allocator, f, ctx, metrics);
if (!left.keep_walking) { if (!left.keep_walking) {
var result = WalkerMut{}; var result = WalkerMut{};
result.err = left.err; result.err = left.err;
result.found = left.found; result.found = left.found;
if (left.replace) |p| { if (left.replace) |p| {
result.replace = Node.new(a, p, node.right) catch |e| return .{ .err = e }; result.replace = Node.new(allocator, p, node.right) catch |e| return .{ .err = e };
} }
return result; return result;
} }
const right = node.right.walk(a, f, ctx, metrics); const right = node.right.walk(allocator, f, ctx, metrics);
return node.merge_results(a, left, right); return node.merge_results(allocator, left, right);
}, },
.leaf => |*l| return f(ctx, l, metrics), .leaf => |*l| return f(ctx, l, metrics),
} }
@ -388,12 +388,12 @@ const Node = union(enum) {
return result.found; return result.found;
} }
fn walk_from_line_begin_internal(self: *const Node, a: Allocator, line: usize, f: WalkerMut.F, ctx: *anyopaque, metrics: Metrics) WalkerMut { fn walk_from_line_begin_internal(self: *const Node, allocator: Allocator, line: usize, f: WalkerMut.F, ctx: *anyopaque, metrics: Metrics) WalkerMut {
switch (self.*) { switch (self.*) {
.node => |*node| { .node => |*node| {
const left_bols = node.weights.bols; const left_bols = node.weights.bols;
if (line >= left_bols) { if (line >= left_bols) {
const right_result = node.right.walk_from_line_begin_internal(a, line - left_bols, f, ctx, metrics); const right_result = node.right.walk_from_line_begin_internal(allocator, line - left_bols, f, ctx, metrics);
if (right_result.replace) |p| { if (right_result.replace) |p| {
var result = WalkerMut{}; var result = WalkerMut{};
result.err = right_result.err; result.err = right_result.err;
@ -402,15 +402,15 @@ const Node = union(enum) {
result.replace = if (p.is_empty()) result.replace = if (p.is_empty())
node.left node.left
else else
Node.new(a, node.left, p) catch |e| return .{ .err = e }; Node.new(allocator, node.left, p) catch |e| return .{ .err = e };
return result; return result;
} else { } else {
return right_result; return right_result;
} }
} }
const left_result = node.left.walk_from_line_begin_internal(a, line, f, ctx, metrics); const left_result = node.left.walk_from_line_begin_internal(allocator, line, f, ctx, metrics);
const right_result = if (left_result.found and left_result.keep_walking) node.right.walk(a, f, ctx, metrics) else WalkerMut{}; const right_result = if (left_result.found and left_result.keep_walking) node.right.walk(allocator, f, ctx, metrics) else WalkerMut{};
return node.merge_results(a, left_result, right_result); return node.merge_results(allocator, left_result, right_result);
}, },
.leaf => |*l| { .leaf => |*l| {
if (line == 0) { if (line == 0) {
@ -427,8 +427,8 @@ const Node = union(enum) {
} }
} }
pub fn walk_from_line_begin(self: *const Node, a: Allocator, line: usize, f: WalkerMut.F, ctx: *anyopaque, metrics: Metrics) !struct { bool, ?Root } { pub fn walk_from_line_begin(self: *const Node, allocator: Allocator, line: usize, f: WalkerMut.F, ctx: *anyopaque, metrics: Metrics) !struct { bool, ?Root } {
const result = self.walk_from_line_begin_internal(a, line, f, ctx, metrics); const result = self.walk_from_line_begin_internal(allocator, line, f, ctx, metrics);
if (result.err) |e| return e; if (result.err) |e| return e;
return .{ result.found, result.replace }; return .{ result.found, result.replace };
} }
@ -608,15 +608,15 @@ const Node = union(enum) {
return result orelse ""; return result orelse "";
} }
pub fn delete_range(self: *const Node, sel: Selection, a: Allocator, size: ?*usize, metrics: Metrics) error{Stop}!Root { pub fn delete_range(self: *const Node, sel: Selection, allocator: Allocator, size: ?*usize, metrics: Metrics) error{Stop}!Root {
var wcwidth: usize = 0; var wcwidth: usize = 0;
_ = self.get_range(sel, null, size, &wcwidth, metrics) catch return error.Stop; _ = self.get_range(sel, null, size, &wcwidth, metrics) catch return error.Stop;
return self.del_chars(sel.begin.row, sel.begin.col, wcwidth, a, metrics) catch return error.Stop; return self.del_chars(sel.begin.row, sel.begin.col, wcwidth, allocator, metrics) catch return error.Stop;
} }
pub fn del_chars(self: *const Node, line: usize, col: usize, count: usize, a: Allocator, metrics_: Metrics) !Root { pub fn del_chars(self: *const Node, line: usize, col: usize, count: usize, allocator: Allocator, metrics_: Metrics) !Root {
const Ctx = struct { const Ctx = struct {
a: Allocator, allocator: Allocator,
col: usize, col: usize,
abs_col: usize = 0, abs_col: usize = 0,
count: usize, count: usize,
@ -625,7 +625,7 @@ const Node = union(enum) {
const ctx = @as(*@This(), @ptrCast(@alignCast(Ctx))); const ctx = @as(*@This(), @ptrCast(@alignCast(Ctx)));
var result = WalkerMut.keep_walking; var result = WalkerMut.keep_walking;
if (ctx.delete_next_bol and ctx.count == 0) { if (ctx.delete_next_bol and ctx.count == 0) {
result.replace = Leaf.new(ctx.a, leaf.buf, false, leaf.eol) catch |e| return .{ .err = e }; result.replace = Leaf.new(ctx.allocator, leaf.buf, false, leaf.eol) catch |e| return .{ .err = e };
result.keep_walking = false; result.keep_walking = false;
ctx.delete_next_bol = false; ctx.delete_next_bol = false;
return result; return result;
@ -645,23 +645,23 @@ const Node = union(enum) {
if (ctx.col == 0) { if (ctx.col == 0) {
if (ctx.count > leaf_wcwidth) { if (ctx.count > leaf_wcwidth) {
ctx.count -= leaf_wcwidth; ctx.count -= leaf_wcwidth;
result.replace = Leaf.new(ctx.a, "", leaf_bol, false) catch |e| return .{ .err = e }; result.replace = Leaf.new(ctx.allocator, "", leaf_bol, false) catch |e| return .{ .err = e };
if (leaf.eol) { if (leaf.eol) {
ctx.count -= 1; ctx.count -= 1;
ctx.delete_next_bol = true; ctx.delete_next_bol = true;
} }
} else if (ctx.count == leaf_wcwidth) { } else if (ctx.count == leaf_wcwidth) {
result.replace = Leaf.new(ctx.a, "", leaf_bol, leaf.eol) catch |e| return .{ .err = e }; result.replace = Leaf.new(ctx.allocator, "", leaf_bol, leaf.eol) catch |e| return .{ .err = e };
ctx.count = 0; ctx.count = 0;
} else { } else {
const pos = leaf.width_to_pos(ctx.count, base_col, metrics) catch |e| return .{ .err = e }; const pos = leaf.width_to_pos(ctx.count, base_col, metrics) catch |e| return .{ .err = e };
result.replace = Leaf.new(ctx.a, leaf.buf[pos..], leaf_bol, leaf.eol) catch |e| return .{ .err = e }; result.replace = Leaf.new(ctx.allocator, leaf.buf[pos..], leaf_bol, leaf.eol) catch |e| return .{ .err = e };
ctx.count = 0; ctx.count = 0;
} }
} else if (ctx.col == leaf_wcwidth) { } else if (ctx.col == leaf_wcwidth) {
if (leaf.eol) { if (leaf.eol) {
ctx.count -= 1; ctx.count -= 1;
result.replace = Leaf.new(ctx.a, leaf.buf, leaf_bol, false) catch |e| return .{ .err = e }; result.replace = Leaf.new(ctx.allocator, leaf.buf, leaf_bol, false) catch |e| return .{ .err = e };
ctx.delete_next_bol = true; ctx.delete_next_bol = true;
} }
ctx.col -= leaf_wcwidth; ctx.col -= leaf_wcwidth;
@ -674,14 +674,14 @@ const Node = union(enum) {
ctx.delete_next_bol = true; ctx.delete_next_bol = true;
break :leaf_eol false; break :leaf_eol false;
} else leaf.eol; } else leaf.eol;
result.replace = Leaf.new(ctx.a, leaf.buf[0..pos], leaf_bol, leaf_eol) catch |e| return .{ .err = e }; result.replace = Leaf.new(ctx.allocator, leaf.buf[0..pos], leaf_bol, leaf_eol) catch |e| return .{ .err = e };
ctx.col = 0; ctx.col = 0;
} else { } else {
const pos = leaf.width_to_pos(ctx.col, base_col, metrics) catch |e| return .{ .err = e }; const pos = leaf.width_to_pos(ctx.col, base_col, metrics) catch |e| return .{ .err = e };
const pos_end = leaf.width_to_pos(ctx.col + ctx.count, base_col, metrics) catch |e| return .{ .err = e }; const pos_end = leaf.width_to_pos(ctx.col + ctx.count, base_col, metrics) catch |e| return .{ .err = e };
const left = Leaf.new(ctx.a, leaf.buf[0..pos], leaf_bol, false) catch |e| return .{ .err = e }; const left = Leaf.new(ctx.allocator, leaf.buf[0..pos], leaf_bol, false) catch |e| return .{ .err = e };
const right = Leaf.new(ctx.a, leaf.buf[pos_end..], false, leaf.eol) catch |e| return .{ .err = e }; const right = Leaf.new(ctx.allocator, leaf.buf[pos_end..], false, leaf.eol) catch |e| return .{ .err = e };
result.replace = Node.new(ctx.a, left, right) catch |e| return .{ .err = e }; result.replace = Node.new(ctx.allocator, left, right) catch |e| return .{ .err = e };
ctx.count = 0; ctx.count = 0;
} }
} }
@ -691,21 +691,21 @@ const Node = union(enum) {
return result; return result;
} }
}; };
var ctx: Ctx = .{ .a = a, .col = col, .count = count }; var ctx: Ctx = .{ .allocator = allocator, .col = col, .count = count };
const found, const root = try self.walk_from_line_begin(a, line, Ctx.walker, &ctx, metrics_); const found, const root = try self.walk_from_line_begin(allocator, line, Ctx.walker, &ctx, metrics_);
return if (found) (root orelse error.Stop) else error.NotFound; return if (found) (root orelse error.Stop) else error.NotFound;
} }
fn merge_in_place(leaves: []const Node, a: Allocator) !Root { fn merge_in_place(leaves: []const Node, allocator: Allocator) !Root {
const len = leaves.len; const len = leaves.len;
if (len == 1) { if (len == 1) {
return &leaves[0]; return &leaves[0];
} }
if (len == 2) { if (len == 2) {
return Node.new(a, &leaves[0], &leaves[1]); return Node.new(allocator, &leaves[0], &leaves[1]);
} }
const mid = len / 2; const mid = len / 2;
return Node.new(a, try merge_in_place(leaves[0..mid], a), try merge_in_place(leaves[mid..], a)); return Node.new(allocator, try merge_in_place(leaves[0..mid], allocator), try merge_in_place(leaves[mid..], allocator));
} }
pub fn get_line(self: *const Node, line: usize, result: *ArrayList(u8), metrics: Metrics) !void { pub fn get_line(self: *const Node, line: usize, result: *ArrayList(u8), metrics: Metrics) !void {
@ -756,12 +756,12 @@ const Node = union(enum) {
line_: usize, line_: usize,
col_: usize, col_: usize,
s: []const u8, s: []const u8,
a: Allocator, allocator: Allocator,
metrics_: Metrics, metrics_: Metrics,
) !struct { usize, usize, Root } { ) !struct { usize, usize, Root } {
var self = self_; var self = self_;
const Ctx = struct { const Ctx = struct {
a: Allocator, allocator: Allocator,
col: usize, col: usize,
abs_col: usize = 0, abs_col: usize = 0,
s: []const u8, s: []const u8,
@ -774,46 +774,46 @@ const Node = union(enum) {
Ctx.abs_col += leaf_wcwidth; Ctx.abs_col += leaf_wcwidth;
if (Ctx.col == 0) { if (Ctx.col == 0) {
const left = Leaf.new(Ctx.a, Ctx.s, leaf.bol, Ctx.eol) catch |e| return .{ .err = e }; const left = Leaf.new(Ctx.allocator, Ctx.s, leaf.bol, Ctx.eol) catch |e| return .{ .err = e };
const right = Leaf.new(Ctx.a, leaf.buf, Ctx.eol, leaf.eol) catch |e| return .{ .err = e }; const right = Leaf.new(Ctx.allocator, leaf.buf, Ctx.eol, leaf.eol) catch |e| return .{ .err = e };
return .{ .replace = Node.new(Ctx.a, left, right) catch |e| return .{ .err = e } }; return .{ .replace = Node.new(Ctx.allocator, left, right) catch |e| return .{ .err = e } };
} }
if (leaf_wcwidth == Ctx.col) { if (leaf_wcwidth == Ctx.col) {
if (leaf.eol and Ctx.eol and Ctx.s.len == 0) { if (leaf.eol and Ctx.eol and Ctx.s.len == 0) {
const left = Leaf.new(Ctx.a, leaf.buf, leaf.bol, true) catch |e| return .{ .err = e }; const left = Leaf.new(Ctx.allocator, leaf.buf, leaf.bol, true) catch |e| return .{ .err = e };
const right = Leaf.new(Ctx.a, Ctx.s, true, true) catch |e| return .{ .err = e }; const right = Leaf.new(Ctx.allocator, Ctx.s, true, true) catch |e| return .{ .err = e };
return .{ .replace = Node.new(Ctx.a, left, right) catch |e| return .{ .err = e } }; return .{ .replace = Node.new(Ctx.allocator, left, right) catch |e| return .{ .err = e } };
} }
const left = Leaf.new(Ctx.a, leaf.buf, leaf.bol, false) catch |e| return .{ .err = e }; const left = Leaf.new(Ctx.allocator, leaf.buf, leaf.bol, false) catch |e| return .{ .err = e };
if (Ctx.eol) { if (Ctx.eol) {
const middle = Leaf.new(Ctx.a, Ctx.s, false, Ctx.eol) catch |e| return .{ .err = e }; const middle = Leaf.new(Ctx.allocator, Ctx.s, false, Ctx.eol) catch |e| return .{ .err = e };
const right = Leaf.new(Ctx.a, "", Ctx.eol, leaf.eol) catch |e| return .{ .err = e }; const right = Leaf.new(Ctx.allocator, "", Ctx.eol, leaf.eol) catch |e| return .{ .err = e };
return .{ .replace = Node.new( return .{ .replace = Node.new(
Ctx.a, Ctx.allocator,
left, left,
Node.new(Ctx.a, middle, right) catch |e| return .{ .err = e }, Node.new(Ctx.allocator, middle, right) catch |e| return .{ .err = e },
) catch |e| return .{ .err = e } }; ) catch |e| return .{ .err = e } };
} else { } else {
const right = Leaf.new(Ctx.a, Ctx.s, false, leaf.eol) catch |e| return .{ .err = e }; const right = Leaf.new(Ctx.allocator, Ctx.s, false, leaf.eol) catch |e| return .{ .err = e };
return .{ .replace = Node.new(Ctx.a, left, right) catch |e| return .{ .err = e } }; return .{ .replace = Node.new(Ctx.allocator, left, right) catch |e| return .{ .err = e } };
} }
} }
if (leaf_wcwidth > Ctx.col) { if (leaf_wcwidth > Ctx.col) {
const pos = leaf.width_to_pos(Ctx.col, base_col, metrics) catch |e| return .{ .err = e }; const pos = leaf.width_to_pos(Ctx.col, base_col, metrics) catch |e| return .{ .err = e };
if (Ctx.eol and Ctx.s.len == 0) { if (Ctx.eol and Ctx.s.len == 0) {
const left = Leaf.new(Ctx.a, leaf.buf[0..pos], leaf.bol, Ctx.eol) catch |e| return .{ .err = e }; const left = Leaf.new(Ctx.allocator, leaf.buf[0..pos], leaf.bol, Ctx.eol) catch |e| return .{ .err = e };
const right = Leaf.new(Ctx.a, leaf.buf[pos..], Ctx.eol, leaf.eol) catch |e| return .{ .err = e }; const right = Leaf.new(Ctx.allocator, leaf.buf[pos..], Ctx.eol, leaf.eol) catch |e| return .{ .err = e };
return .{ .replace = Node.new(Ctx.a, left, right) catch |e| return .{ .err = e } }; return .{ .replace = Node.new(Ctx.allocator, left, right) catch |e| return .{ .err = e } };
} }
const left = Leaf.new(Ctx.a, leaf.buf[0..pos], leaf.bol, false) catch |e| return .{ .err = e }; const left = Leaf.new(Ctx.allocator, leaf.buf[0..pos], leaf.bol, false) catch |e| return .{ .err = e };
const middle = Leaf.new(Ctx.a, Ctx.s, false, Ctx.eol) catch |e| return .{ .err = e }; const middle = Leaf.new(Ctx.allocator, Ctx.s, false, Ctx.eol) catch |e| return .{ .err = e };
const right = Leaf.new(Ctx.a, leaf.buf[pos..], Ctx.eol, leaf.eol) catch |e| return .{ .err = e }; const right = Leaf.new(Ctx.allocator, leaf.buf[pos..], Ctx.eol, leaf.eol) catch |e| return .{ .err = e };
return .{ .replace = Node.new( return .{ .replace = Node.new(
Ctx.a, Ctx.allocator,
left, left,
Node.new(Ctx.a, middle, right) catch |e| return .{ .err = e }, Node.new(Ctx.allocator, middle, right) catch |e| return .{ .err = e },
) catch |e| return .{ .err = e } }; ) catch |e| return .{ .err = e } };
} }
@ -822,7 +822,7 @@ const Node = union(enum) {
} }
}; };
if (s.len == 0) return error.Stop; if (s.len == 0) return error.Stop;
var rest = try a.dupe(u8, s); var rest = try allocator.dupe(u8, s);
var chunk = rest; var chunk = rest;
var line = line_; var line = line_;
var col = col_; var col = col_;
@ -837,8 +837,8 @@ const Node = union(enum) {
rest = &[_]u8{}; rest = &[_]u8{};
need_eol = false; need_eol = false;
} }
var ctx: Ctx = .{ .a = a, .col = col, .s = chunk, .eol = need_eol }; var ctx: Ctx = .{ .allocator = allocator, .col = col, .s = chunk, .eol = need_eol };
const found, const replace = try self.walk_from_line_begin(a, line, Ctx.walker, &ctx, metrics_); const found, const replace = try self.walk_from_line_begin(allocator, line, Ctx.walker, &ctx, metrics_);
if (!found) return error.NotFound; if (!found) return error.NotFound;
if (replace) |root| self = root; if (replace) |root| self = root;
if (need_eol) { if (need_eol) {
@ -866,7 +866,7 @@ const Node = union(enum) {
} }
pub const FindAllCallback = fn (data: *anyopaque, begin_row: usize, begin_col: usize, end_row: usize, end_col: usize) error{Stop}!void; pub const FindAllCallback = fn (data: *anyopaque, begin_row: usize, begin_col: usize, end_row: usize, end_col: usize) error{Stop}!void;
pub fn find_all_ranges(self: *const Node, pattern: []const u8, data: *anyopaque, callback: *const FindAllCallback, a: Allocator) !void { pub fn find_all_ranges(self: *const Node, pattern: []const u8, data: *anyopaque, callback: *const FindAllCallback, allocator: Allocator) !void {
const Ctx = struct { const Ctx = struct {
pattern: []const u8, pattern: []const u8,
data: *anyopaque, data: *anyopaque,
@ -932,9 +932,9 @@ const Node = union(enum) {
.pattern = pattern, .pattern = pattern,
.data = data, .data = data,
.callback = callback, .callback = callback,
.buf = try a.alloc(u8, pattern.len * 2), .buf = try allocator.alloc(u8, pattern.len * 2),
}; };
defer a.free(ctx.buf); defer allocator.free(ctx.buf);
return self.store(ctx.writer()); return self.store(ctx.writer());
} }
@ -1012,33 +1012,33 @@ const Node = union(enum) {
} }
}; };
pub fn create(a: Allocator) !*Self { pub fn create(allocator: Allocator) !*Self {
const self = try a.create(Self); const self = try allocator.create(Self);
const arena_a = if (builtin.is_test) a else std.heap.page_allocator; const arena_a = if (builtin.is_test) allocator else std.heap.page_allocator;
self.* = .{ self.* = .{
.arena = std.heap.ArenaAllocator.init(arena_a), .arena = std.heap.ArenaAllocator.init(arena_a),
.a = self.arena.allocator(), .allocator = self.arena.allocator(),
.external_a = a, .external_allocator = allocator,
.root = try Node.new(self.a, &empty_leaf, &empty_leaf), .root = try Node.new(self.allocator, &empty_leaf, &empty_leaf),
}; };
return self; return self;
} }
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
if (self.file_buf) |buf| self.external_a.free(buf); if (self.file_buf) |buf| self.external_allocator.free(buf);
if (self.leaves_buf) |buf| self.external_a.free(buf); if (self.leaves_buf) |buf| self.external_allocator.free(buf);
self.arena.deinit(); self.arena.deinit();
self.external_a.destroy(self); self.external_allocator.destroy(self);
} }
fn new_file(self: *const Self, file_exists: *bool) !Root { fn new_file(self: *const Self, file_exists: *bool) !Root {
file_exists.* = false; file_exists.* = false;
return Leaf.new(self.a, "", true, false); return Leaf.new(self.allocator, "", true, false);
} }
pub fn load(self: *const Self, reader: anytype, size: usize) !Root { pub fn load(self: *const Self, reader: anytype, size: usize) !Root {
const eol = '\n'; const eol = '\n';
var buf = try self.external_a.alloc(u8, size); var buf = try self.external_allocator.alloc(u8, size);
const self_ = @constCast(self); const self_ = @constCast(self);
self_.file_buf = buf; self_.file_buf = buf;
const read_size = try reader.readAll(buf); const read_size = try reader.readAll(buf);
@ -1053,7 +1053,7 @@ pub fn load(self: *const Self, reader: anytype, size: usize) !Root {
if (buf[i] == eol) leaf_count += 1; if (buf[i] == eol) leaf_count += 1;
} }
var leaves = try self.external_a.alloc(Node, leaf_count); var leaves = try self.external_allocator.alloc(Node, leaf_count);
self_.leaves_buf = leaves; self_.leaves_buf = leaves;
var cur_leaf: usize = 0; var cur_leaf: usize = 0;
var b: usize = 0; var b: usize = 0;
@ -1069,7 +1069,7 @@ pub fn load(self: *const Self, reader: anytype, size: usize) !Root {
leaves[cur_leaf] = .{ .leaf = .{ .buf = line, .bol = true, .eol = false } }; leaves[cur_leaf] = .{ .leaf = .{ .buf = line, .bol = true, .eol = false } };
if (leaves.len != cur_leaf + 1) if (leaves.len != cur_leaf + 1)
return error.Unexpected; return error.Unexpected;
return Node.merge_in_place(leaves, self.a); return Node.merge_in_place(leaves, self.allocator);
} }
pub fn load_from_string(self: *const Self, s: []const u8) !Root { pub fn load_from_string(self: *const Self, s: []const u8) !Root {
@ -1079,7 +1079,7 @@ pub fn load_from_string(self: *const Self, s: []const u8) !Root {
pub fn load_from_string_and_update(self: *Self, file_path: []const u8, s: []const u8) !void { pub fn load_from_string_and_update(self: *Self, file_path: []const u8, s: []const u8) !void {
self.root = try self.load_from_string(s); self.root = try self.load_from_string(s);
self.file_path = try self.a.dupe(u8, file_path); self.file_path = try self.allocator.dupe(u8, file_path);
self.last_save = self.root; self.last_save = self.root;
self.file_exists = false; self.file_exists = false;
} }
@ -1099,13 +1099,13 @@ pub fn load_from_file(self: *const Self, file_path: []const u8, file_exists: *bo
pub fn load_from_file_and_update(self: *Self, file_path: []const u8) !void { pub fn load_from_file_and_update(self: *Self, file_path: []const u8) !void {
var file_exists: bool = false; var file_exists: bool = false;
self.root = try self.load_from_file(file_path, &file_exists); self.root = try self.load_from_file(file_path, &file_exists);
self.file_path = try self.a.dupe(u8, file_path); self.file_path = try self.allocator.dupe(u8, file_path);
self.last_save = self.root; self.last_save = self.root;
self.file_exists = file_exists; self.file_exists = file_exists;
} }
pub fn store_to_string(self: *const Self, a: Allocator) ![]u8 { pub fn store_to_string(self: *const Self, allocator: Allocator) ![]u8 {
var s = try ArrayList(u8).initCapacity(a, self.root.weights_sum().len); var s = try ArrayList(u8).initCapacity(allocator, self.root.weights_sum().len);
try self.root.store(s.writer()); try self.root.store(s.writer());
return s.toOwnedSlice(); return s.toOwnedSlice();
} }
@ -1169,8 +1169,8 @@ pub fn store_undo(self: *Self, meta: []const u8) !void {
} }
fn create_undo(self: *const Self, root: Root, meta_: []const u8) !*UndoNode { fn create_undo(self: *const Self, root: Root, meta_: []const u8) !*UndoNode {
const h = try self.a.create(UndoNode); const h = try self.allocator.create(UndoNode);
const meta = try self.a.dupe(u8, meta_); const meta = try self.allocator.dupe(u8, meta_);
h.* = UndoNode{ h.* = UndoNode{
.root = root, .root = root,
.meta = meta, .meta = meta,
@ -1194,7 +1194,7 @@ fn push_redo_branch(self: *Self) !void {
const r = self.redo_history orelse return; const r = self.redo_history orelse return;
const u = self.undo_history orelse return; const u = self.undo_history orelse return;
const next = u.branches; const next = u.branches;
const b = try self.a.create(UndoBranch); const b = try self.allocator.create(UndoBranch);
b.* = .{ b.* = .{
.redo = r, .redo = r,
.next = next, .next = next,

View file

@ -32,7 +32,7 @@ pub fn deinit(self: *Self) void {
const Process = struct { const Process = struct {
arena: std.heap.ArenaAllocator, arena: std.heap.ArenaAllocator,
a: std.mem.Allocator, allocator: std.mem.Allocator,
receiver: Receiver, receiver: Receiver,
const Receiver = tp.Receiver(*Process); const Receiver = tp.Receiver(*Process);
@ -42,10 +42,10 @@ const Process = struct {
const self = try outer_a.create(Process); const self = try outer_a.create(Process);
self.* = .{ self.* = .{
.arena = std.heap.ArenaAllocator.init(outer_a), .arena = std.heap.ArenaAllocator.init(outer_a),
.a = self.arena.allocator(), .allocator = self.arena.allocator(),
.receiver = Receiver.init(Process.receive, self), .receiver = Receiver.init(Process.receive, self),
}; };
return tp.spawn_link(self.a, self, Process.start, module_name); return tp.spawn_link(self.allocator, self, Process.start, module_name);
} }
fn start(self: *Process) tp.result { fn start(self: *Process) tp.result {
@ -79,26 +79,26 @@ const Process = struct {
const root_src: Buffer.Root = if (root_old_addr == 0) return else @ptrFromInt(root_old_addr); const root_src: Buffer.Root = if (root_old_addr == 0) return else @ptrFromInt(root_old_addr);
var dizzy_edits = std.ArrayListUnmanaged(dizzy.Edit){}; var dizzy_edits = std.ArrayListUnmanaged(dizzy.Edit){};
var dst = std.ArrayList(u8).init(self.a); var dst = std.ArrayList(u8).init(self.allocator);
var src = std.ArrayList(u8).init(self.a); var src = std.ArrayList(u8).init(self.allocator);
var scratch = std.ArrayListUnmanaged(u32){}; var scratch = std.ArrayListUnmanaged(u32){};
var edits = std.ArrayList(Edit).init(self.a); var edits = std.ArrayList(Edit).init(self.allocator);
defer { defer {
dst.deinit(); dst.deinit();
src.deinit(); src.deinit();
scratch.deinit(self.a); scratch.deinit(self.allocator);
dizzy_edits.deinit(self.a); dizzy_edits.deinit(self.allocator);
} }
try root_dst.store(dst.writer()); try root_dst.store(dst.writer());
try root_src.store(src.writer()); try root_src.store(src.writer());
const scratch_len = 4 * (dst.items.len + src.items.len) + 2; const scratch_len = 4 * (dst.items.len + src.items.len) + 2;
try scratch.ensureTotalCapacity(self.a, scratch_len); try scratch.ensureTotalCapacity(self.allocator, scratch_len);
scratch.items.len = scratch_len; scratch.items.len = scratch_len;
try dizzy.PrimitiveSliceDiffer(u8).diff(self.a, &dizzy_edits, src.items, dst.items, scratch.items); try dizzy.PrimitiveSliceDiffer(u8).diff(self.allocator, &dizzy_edits, src.items, dst.items, scratch.items);
if (dizzy_edits.items.len > 2) if (dizzy_edits.items.len > 2)
try edits.ensureTotalCapacity((dizzy_edits.items.len - 1) / 2); try edits.ensureTotalCapacity((dizzy_edits.items.len - 1) / 2);

View file

@ -30,7 +30,7 @@ pub fn deinit(self: *Self) void {
const Process = struct { const Process = struct {
arena: std.heap.ArenaAllocator, arena: std.heap.ArenaAllocator,
a: std.mem.Allocator, allocator: std.mem.Allocator,
backwards: std.ArrayList(Entry), backwards: std.ArrayList(Entry),
current: ?Entry = null, current: ?Entry = null,
forwards: std.ArrayList(Entry), forwards: std.ArrayList(Entry),
@ -49,12 +49,12 @@ const Process = struct {
const self = try outer_a.create(Process); const self = try outer_a.create(Process);
self.* = .{ self.* = .{
.arena = std.heap.ArenaAllocator.init(outer_a), .arena = std.heap.ArenaAllocator.init(outer_a),
.a = self.arena.allocator(), .allocator = self.arena.allocator(),
.backwards = std.ArrayList(Entry).init(self.a), .backwards = std.ArrayList(Entry).init(self.allocator),
.forwards = std.ArrayList(Entry).init(self.a), .forwards = std.ArrayList(Entry).init(self.allocator),
.receiver = Receiver.init(Process.receive, self), .receiver = Receiver.init(Process.receive, self),
}; };
return tp.spawn_link(self.a, self, Process.start, module_name); return tp.spawn_link(self.allocator, self, Process.start, module_name);
} }
fn start(self: *Process) tp.result { fn start(self: *Process) tp.result {
@ -67,7 +67,7 @@ const Process = struct {
self.clear_forwards(); self.clear_forwards();
self.backwards.deinit(); self.backwards.deinit();
self.forwards.deinit(); self.forwards.deinit();
if (self.current) |entry| self.a.free(entry.file_path); if (self.current) |entry| self.allocator.free(entry.file_path);
self.arena.deinit(); self.arena.deinit();
outer_a.destroy(self); outer_a.destroy(self);
} }
@ -81,7 +81,7 @@ const Process = struct {
} }
fn clear_table(self: *Process, table: *std.ArrayList(Entry)) void { fn clear_table(self: *Process, table: *std.ArrayList(Entry)) void {
for (table.items) |entry| self.a.free(entry.file_path); for (table.items) |entry| self.allocator.free(entry.file_path);
table.clearAndFree(); table.clearAndFree();
} }
@ -111,25 +111,25 @@ const Process = struct {
fn update(self: *Process, entry_: Entry) !void { fn update(self: *Process, entry_: Entry) !void {
const entry: Entry = .{ const entry: Entry = .{
.file_path = try self.a.dupe(u8, entry_.file_path), .file_path = try self.allocator.dupe(u8, entry_.file_path),
.cursor = entry_.cursor, .cursor = entry_.cursor,
.selection = entry_.selection, .selection = entry_.selection,
}; };
errdefer self.a.free(entry.file_path); errdefer self.allocator.free(entry.file_path);
defer self.current = entry; defer self.current = entry;
if (isdupe(self.current, entry)) if (isdupe(self.current, entry))
return self.a.free(self.current.?.file_path); return self.allocator.free(self.current.?.file_path);
if (isdupe(self.backwards.getLastOrNull(), entry)) { if (isdupe(self.backwards.getLastOrNull(), entry)) {
if (self.current) |current| self.forwards.append(current) catch {}; if (self.current) |current| self.forwards.append(current) catch {};
const top = self.backwards.pop(); const top = self.backwards.pop();
self.a.free(top.file_path); self.allocator.free(top.file_path);
tp.trace(tp.channel.all, tp.message.fmt(.{ "location", "back", entry.file_path, entry.cursor.row, entry.cursor.col, self.backwards.items.len, self.forwards.items.len })); tp.trace(tp.channel.all, tp.message.fmt(.{ "location", "back", entry.file_path, entry.cursor.row, entry.cursor.col, self.backwards.items.len, self.forwards.items.len }));
} else if (isdupe(self.forwards.getLastOrNull(), entry)) { } else if (isdupe(self.forwards.getLastOrNull(), entry)) {
if (self.current) |current| self.backwards.append(current) catch {}; if (self.current) |current| self.backwards.append(current) catch {};
const top = self.forwards.pop(); const top = self.forwards.pop();
self.a.free(top.file_path); self.allocator.free(top.file_path);
tp.trace(tp.channel.all, tp.message.fmt(.{ "location", "forward", entry.file_path, entry.cursor.row, entry.cursor.col, self.backwards.items.len, self.forwards.items.len })); tp.trace(tp.channel.all, tp.message.fmt(.{ "location", "forward", entry.file_path, entry.cursor.row, entry.cursor.col, self.backwards.items.len, self.forwards.items.len }));
} else if (self.current) |current| { } else if (self.current) |current| {
try self.backwards.append(current); try self.backwards.append(current);

View file

@ -8,7 +8,7 @@ const Self = @This();
pub const max_log_message = tp.max_message_size - 128; pub const max_log_message = tp.max_message_size - 128;
a: std.mem.Allocator, allocator: std.mem.Allocator,
receiver: Receiver, receiver: Receiver,
subscriber: ?tp.pid, subscriber: ?tp.pid,
heap: [32 + 1024]u8, heap: [32 + 1024]u8,
@ -19,11 +19,11 @@ const MsgStoreT = std.DoublyLinkedList([]u8);
const Receiver = tp.Receiver(*Self); const Receiver = tp.Receiver(*Self);
const StartArgs = struct { const StartArgs = struct {
a: std.mem.Allocator, allocator: std.mem.Allocator,
}; };
pub fn spawn(ctx: *tp.context, a: std.mem.Allocator, env: ?*const tp.env) !tp.pid { pub fn spawn(ctx: *tp.context, allocator: std.mem.Allocator, env: ?*const tp.env) !tp.pid {
return try ctx.spawn_link(StartArgs{ .a = a }, Self.start, "log", null, env); return try ctx.spawn_link(StartArgs{ .allocator = allocator }, Self.start, "log", null, env);
} }
fn start(args: StartArgs) tp.result { fn start(args: StartArgs) tp.result {
@ -34,9 +34,9 @@ fn start(args: StartArgs) tp.result {
} }
fn init(args: StartArgs) !*Self { fn init(args: StartArgs) !*Self {
var p = try args.a.create(Self); var p = try args.allocator.create(Self);
p.* = .{ p.* = .{
.a = args.a, .allocator = args.allocator,
.receiver = Receiver.init(Self.receive, p), .receiver = Receiver.init(Self.receive, p),
.subscriber = null, .subscriber = null,
.heap = undefined, .heap = undefined,
@ -48,7 +48,7 @@ fn init(args: StartArgs) !*Self {
fn deinit(self: *const Self) void { fn deinit(self: *const Self) void {
if (self.subscriber) |*s| s.deinit(); if (self.subscriber) |*s| s.deinit();
self.a.destroy(self); self.allocator.destroy(self);
} }
fn log(msg: []const u8) void { fn log(msg: []const u8) void {
@ -56,9 +56,9 @@ fn log(msg: []const u8) void {
} }
fn store(self: *Self, m: tp.message) void { fn store(self: *Self, m: tp.message) void {
const a: std.mem.Allocator = self.fba.allocator(); const allocator: std.mem.Allocator = self.fba.allocator();
const buf: []u8 = a.alloc(u8, m.len()) catch return; const buf: []u8 = allocator.alloc(u8, m.len()) catch return;
var node: *MsgStoreT.Node = a.create(MsgStoreT.Node) catch return; var node: *MsgStoreT.Node = allocator.create(MsgStoreT.Node) catch return;
node.data = buf; node.data = buf;
@memcpy(buf, m.buf); @memcpy(buf, m.buf);
self.msg_store.append(node); self.msg_store.append(node);

View file

@ -349,21 +349,21 @@ pub fn exit(status: u8) noreturn {
const config = @import("config"); const config = @import("config");
pub fn read_config(a: std.mem.Allocator, buf: *?[]const u8) config { pub fn read_config(allocator: std.mem.Allocator, buf: *?[]const u8) config {
const file_name = get_app_config_file_name(application_name) catch return .{}; const file_name = get_app_config_file_name(application_name) catch return .{};
return read_json_config_file(a, file_name, buf) catch .{}; return read_json_config_file(allocator, file_name, buf) catch .{};
} }
fn read_json_config_file(a: std.mem.Allocator, file_name: []const u8, buf: *?[]const u8) !config { fn read_json_config_file(allocator: std.mem.Allocator, file_name: []const u8, buf: *?[]const u8) !config {
const cbor = @import("cbor"); const cbor = @import("cbor");
var file = std.fs.openFileAbsolute(file_name, .{ .mode = .read_only }) catch |e| switch (e) { var file = std.fs.openFileAbsolute(file_name, .{ .mode = .read_only }) catch |e| switch (e) {
error.FileNotFound => return .{}, error.FileNotFound => return .{},
else => return e, else => return e,
}; };
defer file.close(); defer file.close();
const json = try file.readToEndAlloc(a, 64 * 1024); const json = try file.readToEndAlloc(allocator, 64 * 1024);
defer a.free(json); defer allocator.free(json);
const cbor_buf: []u8 = try a.alloc(u8, json.len); const cbor_buf: []u8 = try allocator.alloc(u8, json.len);
buf.* = cbor_buf; buf.* = cbor_buf;
const cb = try cbor.fromJson(json, cbor_buf); const cb = try cbor.fromJson(json, cbor_buf);
var iter = cb; var iter = cb;
@ -383,16 +383,16 @@ fn read_json_config_file(a: std.mem.Allocator, file_name: []const u8, buf: *?[]c
return data; return data;
} }
pub fn write_config(conf: config, a: std.mem.Allocator) !void { pub fn write_config(conf: config, allocator: std.mem.Allocator) !void {
return write_json_file(config, conf, a, try get_app_config_file_name(application_name)); return write_json_file(config, conf, allocator, try get_app_config_file_name(application_name));
} }
fn write_json_file(comptime T: type, data: T, a: std.mem.Allocator, file_name: []const u8) !void { fn write_json_file(comptime T: type, data: T, allocator: std.mem.Allocator, file_name: []const u8) !void {
const cbor = @import("cbor"); const cbor = @import("cbor");
var file = try std.fs.createFileAbsolute(file_name, .{ .truncate = true }); var file = try std.fs.createFileAbsolute(file_name, .{ .truncate = true });
defer file.close(); defer file.close();
var cb = std.ArrayList(u8).init(a); var cb = std.ArrayList(u8).init(allocator);
defer cb.deinit(); defer cb.deinit();
try cbor.writeValue(cb.writer(), data); try cbor.writeValue(cb.writer(), data);

View file

@ -45,14 +45,14 @@ pub fn open(rel_project_directory: []const u8) !void {
return (try get()).pid.send(.{ "open", project_directory }); return (try get()).pid.send(.{ "open", project_directory });
} }
pub fn request_most_recent_file(a: std.mem.Allocator) !?[]const u8 { pub fn request_most_recent_file(allocator: std.mem.Allocator) !?[]const u8 {
const project = tp.env.get().str("project"); const project = tp.env.get().str("project");
if (project.len == 0) if (project.len == 0)
return tp.exit("No project"); return tp.exit("No project");
const rsp = try (try get()).pid.call(a, request_timeout, .{ "request_most_recent_file", project }); const rsp = try (try get()).pid.call(allocator, request_timeout, .{ "request_most_recent_file", project });
defer a.free(rsp.buf); defer allocator.free(rsp.buf);
var file_path: []const u8 = undefined; var file_path: []const u8 = undefined;
return if (try rsp.match(.{tp.extract(&file_path)})) try a.dupe(u8, file_path) else null; return if (try rsp.match(.{tp.extract(&file_path)})) try allocator.dupe(u8, file_path) else null;
} }
pub fn request_recent_files(max: usize) !void { pub fn request_recent_files(max: usize) !void {
@ -62,9 +62,9 @@ pub fn request_recent_files(max: usize) !void {
return (try get()).pid.send(.{ "request_recent_files", project, max }); return (try get()).pid.send(.{ "request_recent_files", project, max });
} }
pub fn request_recent_projects(a: std.mem.Allocator) !tp.message { pub fn request_recent_projects(allocator: std.mem.Allocator) !tp.message {
const project = tp.env.get().str("project"); const project = tp.env.get().str("project");
return (try get()).pid.call(a, request_timeout, .{ "request_recent_projects", project }); return (try get()).pid.call(allocator, request_timeout, .{ "request_recent_projects", project });
} }
pub fn query_recent_files(max: usize, query: []const u8) !void { pub fn query_recent_files(max: usize, query: []const u8) !void {
@ -167,7 +167,7 @@ pub fn get_mru_position(file_path: []const u8) !void {
} }
const Process = struct { const Process = struct {
a: std.mem.Allocator, allocator: std.mem.Allocator,
parent: tp.pid, parent: tp.pid,
logger: log.Logger, logger: log.Logger,
receiver: Receiver, receiver: Receiver,
@ -182,29 +182,29 @@ const Process = struct {
}; };
fn create() !tp.pid { fn create() !tp.pid {
const a = std.heap.c_allocator; const allocator = std.heap.c_allocator;
const self = try a.create(Process); const self = try allocator.create(Process);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.parent = tp.self_pid().clone(), .parent = tp.self_pid().clone(),
.logger = log.logger(module_name), .logger = log.logger(module_name),
.receiver = Receiver.init(Process.receive, self), .receiver = Receiver.init(Process.receive, self),
.projects = ProjectsMap.init(a), .projects = ProjectsMap.init(allocator),
}; };
return tp.spawn_link(self.a, self, Process.start, module_name); return tp.spawn_link(self.allocator, self, Process.start, module_name);
} }
fn deinit(self: *Process) void { fn deinit(self: *Process) void {
var i = self.projects.iterator(); var i = self.projects.iterator();
while (i.next()) |p| { while (i.next()) |p| {
self.a.free(p.key_ptr.*); self.allocator.free(p.key_ptr.*);
p.value_ptr.*.deinit(); p.value_ptr.*.deinit();
self.a.destroy(p.value_ptr.*); self.allocator.destroy(p.value_ptr.*);
} }
self.projects.deinit(); self.projects.deinit();
self.parent.deinit(); self.parent.deinit();
self.logger.deinit(); self.logger.deinit();
self.a.destroy(self); self.allocator.destroy(self);
} }
fn start(self: *Process) tp.result { fn start(self: *Process) tp.result {
@ -313,10 +313,10 @@ const Process = struct {
fn open(self: *Process, project_directory: []const u8) !void { fn open(self: *Process, project_directory: []const u8) !void {
if (self.projects.get(project_directory) == null) { if (self.projects.get(project_directory) == null) {
self.logger.print("opening: {s}", .{project_directory}); self.logger.print("opening: {s}", .{project_directory});
const project = try self.a.create(Project); const project = try self.allocator.create(Project);
project.* = try Project.init(self.a, project_directory); project.* = try Project.init(self.allocator, project_directory);
try self.projects.put(try self.a.dupe(u8, project_directory), project); try self.projects.put(try self.allocator.dupe(u8, project_directory), project);
self.walker = try walk_tree_async(self.a, project_directory); self.walker = try walk_tree_async(self.allocator, project_directory);
self.restore_project(project) catch |e| self.logger.err("restore_project", e); self.restore_project(project) catch |e| self.logger.err("restore_project", e);
project.sort_files_by_mtime(); project.sort_files_by_mtime();
} else { } else {
@ -347,11 +347,11 @@ const Process = struct {
} }
fn request_recent_projects(self: *Process, from: tp.pid_ref, project_directory: []const u8) error{ OutOfMemory, Exit }!void { fn request_recent_projects(self: *Process, from: tp.pid_ref, project_directory: []const u8) error{ OutOfMemory, Exit }!void {
var recent_projects = std.ArrayList(RecentProject).init(self.a); var recent_projects = std.ArrayList(RecentProject).init(self.allocator);
defer recent_projects.deinit(); defer recent_projects.deinit();
self.load_recent_projects(&recent_projects, project_directory) catch {}; self.load_recent_projects(&recent_projects, project_directory) catch {};
self.sort_projects_by_last_used(&recent_projects); self.sort_projects_by_last_used(&recent_projects);
var message = std.ArrayList(u8).init(self.a); var message = std.ArrayList(u8).init(self.allocator);
const writer = message.writer(); const writer = message.writer();
try cbor.writeArrayHeader(writer, recent_projects.items.len); try cbor.writeArrayHeader(writer, recent_projects.items.len);
for (recent_projects.items) |project| for (recent_projects.items) |project|
@ -370,7 +370,7 @@ const Process = struct {
fn request_path_files(self: *Process, from: tp.pid_ref, project_directory: []const u8, max: usize, path: []const u8) error{ OutOfMemory, Exit }!void { fn request_path_files(self: *Process, from: tp.pid_ref, project_directory: []const u8, max: usize, path: []const u8) error{ OutOfMemory, Exit }!void {
const project = self.projects.get(project_directory) orelse return tp.exit("No project"); const project = self.projects.get(project_directory) orelse return tp.exit("No project");
request_path_files_async(self.a, from, project, max, path) catch |e| return tp.exit_error(e, @errorReturnTrace()); request_path_files_async(self.allocator, from, project, max, path) catch |e| return tp.exit_error(e, @errorReturnTrace());
} }
fn did_open(self: *Process, project_directory: []const u8, file_path: []const u8, file_type: []const u8, language_server: []const u8, version: usize, text: []const u8) !void { fn did_open(self: *Process, project_directory: []const u8, file_path: []const u8, file_type: []const u8, language_server: []const u8, version: usize, text: []const u8) !void {
@ -484,8 +484,8 @@ const Process = struct {
fn persist_project(self: *Process, project: *Project) !void { fn persist_project(self: *Process, project: *Project) !void {
self.logger.print("saving: {s}", .{project.name}); self.logger.print("saving: {s}", .{project.name});
const file_name = try get_project_state_file_path(self.a, project); const file_name = try get_project_state_file_path(self.allocator, project);
defer self.a.free(file_name); defer self.allocator.free(file_name);
var file = try std.fs.createFileAbsolute(file_name, .{ .truncate = true }); var file = try std.fs.createFileAbsolute(file_name, .{ .truncate = true });
defer file.close(); defer file.close();
var buffer = std.io.bufferedWriter(file.writer()); var buffer = std.io.bufferedWriter(file.writer());
@ -494,23 +494,23 @@ const Process = struct {
} }
fn restore_project(self: *Process, project: *Project) !void { fn restore_project(self: *Process, project: *Project) !void {
const file_name = try get_project_state_file_path(self.a, project); const file_name = try get_project_state_file_path(self.allocator, project);
defer self.a.free(file_name); defer self.allocator.free(file_name);
var file = std.fs.openFileAbsolute(file_name, .{ .mode = .read_only }) catch |e| switch (e) { var file = std.fs.openFileAbsolute(file_name, .{ .mode = .read_only }) catch |e| switch (e) {
error.FileNotFound => return, error.FileNotFound => return,
else => return e, else => return e,
}; };
defer file.close(); defer file.close();
const stat = try file.stat(); const stat = try file.stat();
var buffer = try self.a.alloc(u8, @intCast(stat.size)); var buffer = try self.allocator.alloc(u8, @intCast(stat.size));
defer self.a.free(buffer); defer self.allocator.free(buffer);
const size = try file.readAll(buffer); const size = try file.readAll(buffer);
try project.restore_state(buffer[0..size]); try project.restore_state(buffer[0..size]);
} }
fn get_project_state_file_path(a: std.mem.Allocator, project: *Project) ![]const u8 { fn get_project_state_file_path(allocator: std.mem.Allocator, project: *Project) ![]const u8 {
const path = project.name; const path = project.name;
var stream = std.ArrayList(u8).init(a); var stream = std.ArrayList(u8).init(allocator);
const writer = stream.writer(); const writer = stream.writer();
_ = try writer.write(try root.get_state_dir()); _ = try writer.write(try root.get_state_dir());
_ = try writer.writeByte(std.fs.path.sep); _ = try writer.writeByte(std.fs.path.sep);
@ -532,7 +532,7 @@ const Process = struct {
} }
fn load_recent_projects(self: *Process, recent_projects: *std.ArrayList(RecentProject), project_directory: []const u8) !void { fn load_recent_projects(self: *Process, recent_projects: *std.ArrayList(RecentProject), project_directory: []const u8) !void {
var path = std.ArrayList(u8).init(self.a); var path = std.ArrayList(u8).init(self.allocator);
defer path.deinit(); defer path.deinit();
const writer = path.writer(); const writer = path.writer();
_ = try writer.write(try root.get_state_dir()); _ = try writer.write(try root.get_state_dir());
@ -555,7 +555,7 @@ const Process = struct {
recent_projects: *std.ArrayList(RecentProject), recent_projects: *std.ArrayList(RecentProject),
project_directory: []const u8, project_directory: []const u8,
) !void { ) !void {
var path = std.ArrayList(u8).init(self.a); var path = std.ArrayList(u8).init(self.allocator);
defer path.deinit(); defer path.deinit();
const writer = path.writer(); const writer = path.writer();
_ = try writer.write(state_dir); _ = try writer.write(state_dir);
@ -565,15 +565,15 @@ const Process = struct {
var file = try std.fs.openFileAbsolute(path.items, .{ .mode = .read_only }); var file = try std.fs.openFileAbsolute(path.items, .{ .mode = .read_only });
defer file.close(); defer file.close();
const stat = try file.stat(); const stat = try file.stat();
const buffer = try self.a.alloc(u8, @intCast(stat.size)); const buffer = try self.allocator.alloc(u8, @intCast(stat.size));
defer self.a.free(buffer); defer self.allocator.free(buffer);
_ = try file.readAll(buffer); _ = try file.readAll(buffer);
var iter: []const u8 = buffer; var iter: []const u8 = buffer;
var name: []const u8 = undefined; var name: []const u8 = undefined;
if (cbor.matchValue(&iter, tp.extract(&name)) catch return) { if (cbor.matchValue(&iter, tp.extract(&name)) catch return) {
const last_used = if (std.mem.eql(u8, project_directory, name)) std.math.maxInt(@TypeOf(stat.mtime)) else stat.mtime; const last_used = if (std.mem.eql(u8, project_directory, name)) std.math.maxInt(@TypeOf(stat.mtime)) else stat.mtime;
(try recent_projects.addOne()).* = .{ .name = try self.a.dupe(u8, name), .last_used = last_used }; (try recent_projects.addOne()).* = .{ .name = try self.allocator.dupe(u8, name), .last_used = last_used };
} }
} }
@ -589,7 +589,7 @@ const Process = struct {
fn request_path_files_async(a_: std.mem.Allocator, parent_: tp.pid_ref, project_: *Project, max_: usize, path_: []const u8) !void { fn request_path_files_async(a_: std.mem.Allocator, parent_: tp.pid_ref, project_: *Project, max_: usize, path_: []const u8) !void {
return struct { return struct {
a: std.mem.Allocator, allocator: std.mem.Allocator,
project_name: []const u8, project_name: []const u8,
path: []const u8, path: []const u8,
parent: tp.pid, parent: tp.pid,
@ -599,20 +599,20 @@ fn request_path_files_async(a_: std.mem.Allocator, parent_: tp.pid_ref, project_
const path_files = @This(); const path_files = @This();
const Receiver = tp.Receiver(*path_files); const Receiver = tp.Receiver(*path_files);
fn spawn_link(a: std.mem.Allocator, parent: tp.pid_ref, project: *Project, max: usize, path: []const u8) !void { fn spawn_link(allocator: std.mem.Allocator, parent: tp.pid_ref, project: *Project, max: usize, path: []const u8) !void {
const self = try a.create(path_files); const self = try allocator.create(path_files);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.project_name = try a.dupe(u8, project.name), .project_name = try allocator.dupe(u8, project.name),
.path = try if (std.fs.path.isAbsolute(path)) .path = try if (std.fs.path.isAbsolute(path))
a.dupe(u8, path) allocator.dupe(u8, path)
else else
std.fs.path.join(a, &[_][]const u8{ project.name, path }), std.fs.path.join(allocator, &[_][]const u8{ project.name, path }),
.parent = parent.clone(), .parent = parent.clone(),
.max = max, .max = max,
.dir = try std.fs.cwd().openDir(self.path, .{ .iterate = true }), .dir = try std.fs.cwd().openDir(self.path, .{ .iterate = true }),
}; };
const pid = try tp.spawn_link(a, self, path_files.start, module_name ++ ".path_files"); const pid = try tp.spawn_link(allocator, self, path_files.start, module_name ++ ".path_files");
pid.deinit(); pid.deinit();
} }
@ -627,8 +627,8 @@ fn request_path_files_async(a_: std.mem.Allocator, parent_: tp.pid_ref, project_
fn deinit(self: *path_files) void { fn deinit(self: *path_files) void {
self.dir.close(); self.dir.close();
self.a.free(self.path); self.allocator.free(self.path);
self.a.free(self.project_name); self.allocator.free(self.project_name);
self.parent.deinit(); self.parent.deinit();
} }
@ -653,7 +653,7 @@ fn request_path_files_async(a_: std.mem.Allocator, parent_: tp.pid_ref, project_
fn walk_tree_async(a_: std.mem.Allocator, root_path_: []const u8) !tp.pid { fn walk_tree_async(a_: std.mem.Allocator, root_path_: []const u8) !tp.pid {
return struct { return struct {
a: std.mem.Allocator, allocator: std.mem.Allocator,
root_path: []const u8, root_path: []const u8,
parent: tp.pid, parent: tp.pid,
receiver: Receiver, receiver: Receiver,
@ -663,17 +663,17 @@ fn walk_tree_async(a_: std.mem.Allocator, root_path_: []const u8) !tp.pid {
const tree_walker = @This(); const tree_walker = @This();
const Receiver = tp.Receiver(*tree_walker); const Receiver = tp.Receiver(*tree_walker);
fn spawn_link(a: std.mem.Allocator, root_path: []const u8) !tp.pid { fn spawn_link(allocator: std.mem.Allocator, root_path: []const u8) !tp.pid {
const self = try a.create(tree_walker); const self = try allocator.create(tree_walker);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.root_path = try a.dupe(u8, root_path), .root_path = try allocator.dupe(u8, root_path),
.parent = tp.self_pid().clone(), .parent = tp.self_pid().clone(),
.receiver = Receiver.init(tree_walker.receive, self), .receiver = Receiver.init(tree_walker.receive, self),
.dir = try std.fs.cwd().openDir(self.root_path, .{ .iterate = true }), .dir = try std.fs.cwd().openDir(self.root_path, .{ .iterate = true }),
.walker = try walk_filtered(self.dir, self.a), .walker = try walk_filtered(self.dir, self.allocator),
}; };
return tp.spawn_link(a, self, tree_walker.start, module_name ++ ".tree_walker"); return tp.spawn_link(allocator, self, tree_walker.start, module_name ++ ".tree_walker");
} }
fn start(self: *tree_walker) tp.result { fn start(self: *tree_walker) tp.result {
@ -687,7 +687,7 @@ fn walk_tree_async(a_: std.mem.Allocator, root_path_: []const u8) !tp.pid {
fn deinit(self: *tree_walker) void { fn deinit(self: *tree_walker) void {
self.walker.deinit(); self.walker.deinit();
self.dir.close(); self.dir.close();
self.a.free(self.root_path); self.allocator.free(self.root_path);
self.parent.deinit(); self.parent.deinit();
} }

View file

@ -20,7 +20,7 @@ const event_type = input.event_type;
const Self = @This(); const Self = @This();
pub const log_name = "vaxis"; pub const log_name = "vaxis";
a: std.mem.Allocator, allocator: std.mem.Allocator,
tty: vaxis.Tty, tty: vaxis.Tty,
vx: vaxis.Vaxis, vx: vaxis.Vaxis,
@ -49,7 +49,7 @@ const Event = union(enum) {
focus_in, focus_in,
}; };
pub fn init(a: std.mem.Allocator, handler_ctx: *anyopaque, no_alternate: bool) !Self { pub fn init(allocator: std.mem.Allocator, handler_ctx: *anyopaque, no_alternate: bool) !Self {
const opts: vaxis.Vaxis.Options = .{ const opts: vaxis.Vaxis.Options = .{
.kitty_keyboard_flags = .{ .kitty_keyboard_flags = .{
.disambiguate = true, .disambiguate = true,
@ -58,16 +58,16 @@ pub fn init(a: std.mem.Allocator, handler_ctx: *anyopaque, no_alternate: bool) !
.report_all_as_ctl_seqs = true, .report_all_as_ctl_seqs = true,
.report_text = true, .report_text = true,
}, },
.system_clipboard_allocator = a, .system_clipboard_allocator = allocator,
}; };
return .{ return .{
.a = a, .allocator = allocator,
.tty = try vaxis.Tty.init(), .tty = try vaxis.Tty.init(),
.vx = try vaxis.init(a, opts), .vx = try vaxis.init(allocator, opts),
.no_alternate = no_alternate, .no_alternate = no_alternate,
.event_buffer = std.ArrayList(u8).init(a), .event_buffer = std.ArrayList(u8).init(allocator),
.input_buffer = std.ArrayList(u8).init(a), .input_buffer = std.ArrayList(u8).init(allocator),
.bracketed_paste_buffer = std.ArrayList(u8).init(a), .bracketed_paste_buffer = std.ArrayList(u8).init(allocator),
.handler_ctx = handler_ctx, .handler_ctx = handler_ctx,
.logger = log.logger(log_name), .logger = log.logger(log_name),
.loop = undefined, .loop = undefined,
@ -77,7 +77,7 @@ pub fn init(a: std.mem.Allocator, handler_ctx: *anyopaque, no_alternate: bool) !
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
panic_cleanup = null; panic_cleanup = null;
self.loop.stop(); self.loop.stop();
self.vx.deinit(self.a, self.tty.anyWriter()); self.vx.deinit(self.allocator, self.tty.anyWriter());
self.tty.deinit(); self.tty.deinit();
self.bracketed_paste_buffer.deinit(); self.bracketed_paste_buffer.deinit();
self.input_buffer.deinit(); self.input_buffer.deinit();
@ -85,7 +85,7 @@ pub fn deinit(self: *Self) void {
} }
var panic_cleanup: ?struct { var panic_cleanup: ?struct {
a: std.mem.Allocator, allocator: std.mem.Allocator,
tty: *vaxis.Tty, tty: *vaxis.Tty,
vx: *vaxis.Vaxis, vx: *vaxis.Vaxis,
} = null; } = null;
@ -93,7 +93,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, ret_
const cleanup = panic_cleanup; const cleanup = panic_cleanup;
panic_cleanup = null; panic_cleanup = null;
if (cleanup) |self| { if (cleanup) |self| {
self.vx.deinit(self.a, self.tty.anyWriter()); self.vx.deinit(self.allocator, self.tty.anyWriter());
self.tty.deinit(); self.tty.deinit();
} }
return std.builtin.default_panic(msg, error_return_trace, ret_addr); return std.builtin.default_panic(msg, error_return_trace, ret_addr);
@ -102,7 +102,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, ret_
pub fn run(self: *Self) !void { pub fn run(self: *Self) !void {
self.vx.sgr = .legacy; self.vx.sgr = .legacy;
panic_cleanup = .{ .a = self.a, .tty = &self.tty, .vx = &self.vx }; panic_cleanup = .{ .allocator = self.allocator, .tty = &self.tty, .vx = &self.vx };
if (!self.no_alternate) try self.vx.enterAltScreen(self.tty.anyWriter()); if (!self.no_alternate) try self.vx.enterAltScreen(self.tty.anyWriter());
if (builtin.os.tag == .windows) { if (builtin.os.tag == .windows) {
try self.resize(.{ .rows = 25, .cols = 80, .x_pixel = 0, .y_pixel = 0 }); // dummy resize to fully init vaxis try self.resize(.{ .rows = 25, .cols = 80, .x_pixel = 0, .y_pixel = 0 }); // dummy resize to fully init vaxis
@ -128,7 +128,7 @@ pub fn sigwinch(self: *Self) !void {
} }
fn resize(self: *Self, ws: vaxis.Winsize) !void { fn resize(self: *Self, ws: vaxis.Winsize) !void {
try self.vx.resize(self.a, self.tty.anyWriter(), ws); try self.vx.resize(self.allocator, self.tty.anyWriter(), ws);
self.vx.queueRefresh(); self.vx.queueRefresh();
if (self.dispatch_event) |f| f(self.handler_ctx, try self.fmtmsg(.{"resize"})); if (self.dispatch_event) |f| f(self.handler_ctx, try self.fmtmsg(.{"resize"}));
} }
@ -336,7 +336,7 @@ pub fn set_terminal_working_directory(self: *Self, absolute_path: []const u8) vo
pub fn copy_to_system_clipboard(self: *Self, text: []const u8) void { pub fn copy_to_system_clipboard(self: *Self, text: []const u8) void {
var bufferedWriter = self.tty.bufferedWriter(); var bufferedWriter = self.tty.bufferedWriter();
self.vx.copyToSystemClipboard(bufferedWriter.writer().any(), text, self.a) catch |e| log.logger(log_name).err("copy_to_system_clipboard", e); self.vx.copyToSystemClipboard(bufferedWriter.writer().any(), text, self.allocator) catch |e| log.logger(log_name).err("copy_to_system_clipboard", e);
bufferedWriter.flush() catch @panic("flush failed"); bufferedWriter.flush() catch @panic("flush failed");
} }

View file

@ -15,18 +15,18 @@ pub const Writer = std.io.Writer(*Self, Error, write);
pub const BufferedWriter = std.io.BufferedWriter(max_chunk_size, Writer); pub const BufferedWriter = std.io.BufferedWriter(max_chunk_size, Writer);
pub const Error = error{ OutOfMemory, Exit, ThespianSpawnFailed, Closed }; pub const Error = error{ OutOfMemory, Exit, ThespianSpawnFailed, Closed };
pub const FindF = fn (a: std.mem.Allocator, query: []const u8, tag: [:0]const u8) Error!Self; pub const FindF = fn (allocator: std.mem.Allocator, query: []const u8, tag: [:0]const u8) Error!Self;
pub fn find_in_stdin(a: std.mem.Allocator, query: []const u8, tag: [:0]const u8) Error!Self { pub fn find_in_stdin(allocator: std.mem.Allocator, query: []const u8, tag: [:0]const u8) Error!Self {
return create(a, query, tag, .Pipe); return create(allocator, query, tag, .Pipe);
} }
pub fn find_in_files(a: std.mem.Allocator, query: []const u8, tag: [:0]const u8) !Self { pub fn find_in_files(allocator: std.mem.Allocator, query: []const u8, tag: [:0]const u8) !Self {
return create(a, query, tag, .Close); return create(allocator, query, tag, .Close);
} }
fn create(a: std.mem.Allocator, query: []const u8, tag: [:0]const u8, stdin_behavior: std.process.Child.StdIo) !Self { fn create(allocator: std.mem.Allocator, query: []const u8, tag: [:0]const u8, stdin_behavior: std.process.Child.StdIo) !Self {
return .{ .pid = try Process.create(a, query, tag, stdin_behavior), .stdin_behavior = stdin_behavior }; return .{ .pid = try Process.create(allocator, query, tag, stdin_behavior), .stdin_behavior = stdin_behavior };
} }
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
@ -71,7 +71,7 @@ pub fn bufferedWriter(self: *Self) BufferedWriter {
} }
const Process = struct { const Process = struct {
a: std.mem.Allocator, allocator: std.mem.Allocator,
query: []const u8, query: []const u8,
receiver: Receiver, receiver: Receiver,
sp: ?tp.subprocess = null, sp: ?tp.subprocess = null,
@ -84,25 +84,25 @@ const Process = struct {
const Receiver = tp.Receiver(*Process); const Receiver = tp.Receiver(*Process);
pub fn create(a: std.mem.Allocator, query: []const u8, tag: [:0]const u8, stdin_behavior: std.process.Child.StdIo) !tp.pid { pub fn create(allocator: std.mem.Allocator, query: []const u8, tag: [:0]const u8, stdin_behavior: std.process.Child.StdIo) !tp.pid {
const self = try a.create(Process); const self = try allocator.create(Process);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.query = try a.dupe(u8, query), .query = try allocator.dupe(u8, query),
.receiver = Receiver.init(receive, self), .receiver = Receiver.init(receive, self),
.output = std.ArrayList(u8).init(a), .output = std.ArrayList(u8).init(allocator),
.parent = tp.self_pid().clone(), .parent = tp.self_pid().clone(),
.tag = try a.dupeZ(u8, tag), .tag = try allocator.dupeZ(u8, tag),
.logger = log.logger(@typeName(Self)), .logger = log.logger(@typeName(Self)),
.stdin_behavior = stdin_behavior, .stdin_behavior = stdin_behavior,
}; };
return tp.spawn_link(self.a, self, Process.start, tag); return tp.spawn_link(self.allocator, self, Process.start, tag);
} }
fn deinit(self: *Process) void { fn deinit(self: *Process) void {
self.output.deinit(); self.output.deinit();
self.logger.deinit(); self.logger.deinit();
self.a.free(self.query); self.allocator.free(self.query);
self.close() catch {}; self.close() catch {};
} }
@ -122,7 +122,7 @@ const Process = struct {
"--json", "--json",
self.query, self.query,
}); });
self.sp = tp.subprocess.init(self.a, args, module_name, self.stdin_behavior) catch |e| return tp.exit_error(e, @errorReturnTrace()); self.sp = tp.subprocess.init(self.allocator, args, module_name, self.stdin_behavior) catch |e| return tp.exit_error(e, @errorReturnTrace());
tp.receive(&self.receiver); tp.receive(&self.receiver);
} }
@ -167,7 +167,7 @@ const Process = struct {
} }
fn dispatch(self: *Process, m: tp.message) !void { fn dispatch(self: *Process, m: tp.message) !void {
var obj = std.json.ObjectMap.init(self.a); var obj = std.json.ObjectMap.init(self.allocator);
defer obj.deinit(); defer obj.deinit();
if (try m.match(tp.extract(&obj))) { if (try m.match(tp.extract(&obj))) {
if (obj.get("type")) |*val| { if (obj.get("type")) |*val| {

View file

@ -9,8 +9,8 @@ const Self = @This();
const module_name = @typeName(Self); const module_name = @typeName(Self);
pub const Error = error{ OutOfMemory, Exit }; pub const Error = error{ OutOfMemory, Exit };
pub fn create(a: std.mem.Allocator) Error!Self { pub fn create(allocator: std.mem.Allocator) Error!Self {
return .{ .pid = try Process.create(a) }; return .{ .pid = try Process.create(allocator) };
} }
pub fn from_pid(pid: tp.pid_ref) Error!Self { pub fn from_pid(pid: tp.pid_ref) Error!Self {
@ -37,17 +37,17 @@ pub fn shutdown(self: *Self) void {
// } // }
const Process = struct { const Process = struct {
a: std.mem.Allocator, allocator: std.mem.Allocator,
parent: tp.pid, parent: tp.pid,
logger: log.Logger, logger: log.Logger,
receiver: Receiver, receiver: Receiver,
const Receiver = tp.Receiver(*Process); const Receiver = tp.Receiver(*Process);
pub fn create(a: std.mem.Allocator) Error!tp.pid { pub fn create(allocator: std.mem.Allocator) Error!tp.pid {
const self = try a.create(Process); const self = try allocator.create(Process);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.parent = tp.self_pid().clone(), .parent = tp.self_pid().clone(),
.logger = log.logger(module_name), .logger = log.logger(module_name),
.receiver = Receiver.init(Process.receive, self), .receiver = Receiver.init(Process.receive, self),

View file

@ -18,7 +18,7 @@ const Parser = treez.Parser;
const Query = treez.Query; const Query = treez.Query;
pub const Node = treez.Node; pub const Node = treez.Node;
a: std.mem.Allocator, allocator: std.mem.Allocator,
lang: *const Language, lang: *const Language,
file_type: *const FileType, file_type: *const FileType,
parser: *Parser, parser: *Parser,
@ -26,10 +26,10 @@ query: *Query,
injections: *Query, injections: *Query,
tree: ?*treez.Tree = null, tree: ?*treez.Tree = null,
pub fn create(file_type: *const FileType, a: std.mem.Allocator, content: []const u8) !*Self { pub fn create(file_type: *const FileType, allocator: std.mem.Allocator, content: []const u8) !*Self {
const self = try a.create(Self); const self = try allocator.create(Self);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.lang = file_type.lang_fn() orelse std.debug.panic("tree-sitter parser function failed for language: {s}", .{file_type.name}), .lang = file_type.lang_fn() orelse std.debug.panic("tree-sitter parser function failed for language: {s}", .{file_type.name}),
.file_type = file_type, .file_type = file_type,
.parser = try Parser.create(), .parser = try Parser.create(),
@ -42,21 +42,21 @@ pub fn create(file_type: *const FileType, a: std.mem.Allocator, content: []const
return self; return self;
} }
pub fn create_file_type(a: std.mem.Allocator, content: []const u8, lang_name: []const u8) !*Self { pub fn create_file_type(allocator: std.mem.Allocator, content: []const u8, lang_name: []const u8) !*Self {
const file_type = FileType.get_by_name(lang_name) orelse return error.NotFound; const file_type = FileType.get_by_name(lang_name) orelse return error.NotFound;
return create(file_type, a, content); return create(file_type, allocator, content);
} }
pub fn create_guess_file_type(a: std.mem.Allocator, content: []const u8, file_path: ?[]const u8) !*Self { pub fn create_guess_file_type(allocator: std.mem.Allocator, content: []const u8, file_path: ?[]const u8) !*Self {
const file_type = FileType.guess(file_path, content) orelse return error.NotFound; const file_type = FileType.guess(file_path, content) orelse return error.NotFound;
return create(file_type, a, content); return create(file_type, allocator, content);
} }
pub fn destroy(self: *Self) void { pub fn destroy(self: *Self) void {
if (self.tree) |tree| tree.destroy(); if (self.tree) |tree| tree.destroy();
self.query.destroy(); self.query.destroy();
self.parser.destroy(); self.parser.destroy();
self.a.destroy(self); self.allocator.destroy(self);
} }
pub fn refresh_full(self: *Self, content: []const u8) !void { pub fn refresh_full(self: *Self, content: []const u8) !void {

View file

@ -55,8 +55,8 @@ fn remove_prefix_in_line(prefix: []const u8, text: []const u8, writer: TextWrite
} }
} }
pub fn toggle_prefix_in_text(prefix: []const u8, text: []const u8, a: std.mem.Allocator) ![]const u8 { pub fn toggle_prefix_in_text(prefix: []const u8, text: []const u8, allocator: std.mem.Allocator) ![]const u8 {
var result = try std.ArrayList(u8).initCapacity(a, prefix.len + text.len); var result = try std.ArrayList(u8).initCapacity(allocator, prefix.len + text.len);
const writer = result.writer(); const writer = result.writer();
var pos: usize = 0; var pos: usize = 0;
var prefix_pos: usize = std.math.maxInt(usize); var prefix_pos: usize = std.math.maxInt(usize);

View file

@ -46,28 +46,28 @@ pub fn Options(context: type) type {
}; };
} }
pub fn create(ctx_type: type, a: std.mem.Allocator, parent: Plane, opts: Options(ctx_type)) error{OutOfMemory}!*State(ctx_type) { pub fn create(ctx_type: type, allocator: std.mem.Allocator, parent: Plane, opts: Options(ctx_type)) error{OutOfMemory}!*State(ctx_type) {
const Self = State(ctx_type); const Self = State(ctx_type);
const self = try a.create(Self); const self = try allocator.create(Self);
var n = try Plane.init(&opts.pos.opts(@typeName(Self)), parent); var n = try Plane.init(&opts.pos.opts(@typeName(Self)), parent);
errdefer n.deinit(); errdefer n.deinit();
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.parent = parent, .parent = parent,
.plane = n, .plane = n,
.opts = opts, .opts = opts,
}; };
self.opts.label = try self.a.dupe(u8, opts.label); self.opts.label = try self.allocator.dupe(u8, opts.label);
return self; return self;
} }
pub fn create_widget(ctx_type: type, a: std.mem.Allocator, parent: Plane, opts: Options(ctx_type)) error{OutOfMemory}!Widget { pub fn create_widget(ctx_type: type, allocator: std.mem.Allocator, parent: Plane, opts: Options(ctx_type)) error{OutOfMemory}!Widget {
return Widget.to(try create(ctx_type, a, parent, opts)); return Widget.to(try create(ctx_type, allocator, parent, opts));
} }
pub fn State(ctx_type: type) type { pub fn State(ctx_type: type) type {
return struct { return struct {
a: std.mem.Allocator, allocator: std.mem.Allocator,
parent: Plane, parent: Plane,
plane: Plane, plane: Plane,
active: bool = false, active: bool = false,
@ -77,10 +77,10 @@ pub fn State(ctx_type: type) type {
const Self = @This(); const Self = @This();
pub const Context = ctx_type; pub const Context = ctx_type;
pub fn deinit(self: *Self, a: std.mem.Allocator) void { pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
self.a.free(self.opts.label); self.allocator.free(self.opts.label);
self.plane.deinit(); self.plane.deinit();
a.destroy(self); allocator.destroy(self);
} }
pub fn layout(self: *Self) Widget.Layout { pub fn layout(self: *Self) Widget.Layout {

View file

@ -96,9 +96,9 @@ pub fn send(self: Self, from_: tp.pid_ref, m: tp.message) tp.result {
return self.vtable.send(self.ptr, from_, m); return self.vtable.send(self.ptr, from_, m);
} }
pub fn empty(a: Allocator) !Self { pub fn empty(allocator: Allocator) !Self {
const child: type = struct {}; const child: type = struct {};
const widget = try a.create(child); const widget = try allocator.create(child);
widget.* = .{}; widget.* = .{};
return .{ return .{
.ptr = widget, .ptr = widget,
@ -106,8 +106,8 @@ pub fn empty(a: Allocator) !Self {
.vtable = comptime &.{ .vtable = comptime &.{
.type_name = @typeName(child), .type_name = @typeName(child),
.deinit = struct { .deinit = struct {
pub fn deinit(ctx: *anyopaque, a_: Allocator) void { pub fn deinit(ctx: *anyopaque, allocator_: Allocator) void {
return a_.destroy(@as(*child, @ptrCast(@alignCast(ctx)))); return allocator_.destroy(@as(*child, @ptrCast(@alignCast(ctx))));
} }
}.deinit, }.deinit,
.send = struct { .send = struct {
@ -120,14 +120,14 @@ pub fn empty(a: Allocator) !Self {
} }
pub const List = struct { pub const List = struct {
a: Allocator, allocator: Allocator,
list: ArrayList(EventHandler), list: ArrayList(EventHandler),
recursion_check: bool = false, recursion_check: bool = false,
pub fn init(a: Allocator) List { pub fn init(allocator: Allocator) List {
return .{ return .{
.a = a, .allocator = allocator,
.list = ArrayList(EventHandler).init(a), .list = ArrayList(EventHandler).init(allocator),
}; };
} }

View file

@ -48,17 +48,17 @@ pub fn Options(context: type) type {
}; };
} }
pub fn create(ctx_type: type, a: std.mem.Allocator, parent: Plane, opts: Options(ctx_type)) !Widget { pub fn create(ctx_type: type, allocator: std.mem.Allocator, parent: Plane, opts: Options(ctx_type)) !Widget {
const Self = State(ctx_type); const Self = State(ctx_type);
const self = try a.create(Self); const self = try allocator.create(Self);
var n = try Plane.init(&opts.pos.opts(@typeName(Self)), parent); var n = try Plane.init(&opts.pos.opts(@typeName(Self)), parent);
errdefer n.deinit(); errdefer n.deinit();
self.* = .{ self.* = .{
.parent = parent, .parent = parent,
.plane = n, .plane = n,
.opts = opts, .opts = opts,
.label = std.ArrayList(u8).init(a), .label = std.ArrayList(u8).init(allocator),
.text = std.ArrayList(u8).init(a), .text = std.ArrayList(u8).init(allocator),
}; };
try self.label.appendSlice(self.opts.label); try self.label.appendSlice(self.opts.label);
self.opts.label = self.label.items; self.opts.label = self.label.items;
@ -79,11 +79,11 @@ pub fn State(ctx_type: type) type {
const Self = @This(); const Self = @This();
pub const Context = ctx_type; pub const Context = ctx_type;
pub fn deinit(self: *Self, a: std.mem.Allocator) void { pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
self.text.deinit(); self.text.deinit();
self.label.deinit(); self.label.deinit();
self.plane.deinit(); self.plane.deinit();
a.destroy(self); allocator.destroy(self);
} }
pub fn layout(self: *Self) Widget.Layout { pub fn layout(self: *Self) Widget.Layout {

View file

@ -50,15 +50,15 @@ pub fn Options(context: type) type {
}; };
} }
pub fn create(ctx_type: type, a: std.mem.Allocator, parent: Widget, opts: Options(ctx_type)) !*State(ctx_type) { pub fn create(ctx_type: type, allocator: std.mem.Allocator, parent: Widget, opts: Options(ctx_type)) !*State(ctx_type) {
const self = try a.create(State(ctx_type)); const self = try allocator.create(State(ctx_type));
const container = try WidgetList.createH(a, parent, @typeName(@This()), .dynamic); const container = try WidgetList.createH(allocator, parent, @typeName(@This()), .dynamic);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.menu = try WidgetList.createV(a, container.widget(), @typeName(@This()), .dynamic), .menu = try WidgetList.createV(allocator, container.widget(), @typeName(@This()), .dynamic),
.container = container, .container = container,
.container_widget = container.widget(), .container_widget = container.widget(),
.scrollbar = if (opts.on_scroll) |on_scroll| (try scrollbar_v.create(a, parent, null, on_scroll)).dynamic_cast(scrollbar_v).? else null, .scrollbar = if (opts.on_scroll) |on_scroll| (try scrollbar_v.create(allocator, parent, null, on_scroll)).dynamic_cast(scrollbar_v).? else null,
.opts = opts, .opts = opts,
}; };
self.menu.ctx = self; self.menu.ctx = self;
@ -72,7 +72,7 @@ pub fn create(ctx_type: type, a: std.mem.Allocator, parent: Widget, opts: Option
pub fn State(ctx_type: type) type { pub fn State(ctx_type: type) type {
return struct { return struct {
a: std.mem.Allocator, allocator: std.mem.Allocator,
menu: *WidgetList, menu: *WidgetList,
container: *WidgetList, container: *WidgetList,
container_widget: Widget, container_widget: Widget,
@ -87,9 +87,9 @@ pub fn State(ctx_type: type) type {
const options_type = Options(ctx_type); const options_type = Options(ctx_type);
const button_type = Button.State(*Self); const button_type = Button.State(*Self);
pub fn deinit(self: *Self, a: std.mem.Allocator) void { pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
self.menu.deinit(a); self.menu.deinit(allocator);
a.destroy(self); allocator.destroy(self);
} }
pub fn add_header(self: *Self, w_: Widget) !*Widget { pub fn add_header(self: *Self, w_: Widget) !*Widget {
@ -99,7 +99,7 @@ pub fn State(ctx_type: type) type {
} }
pub fn add_item(self: *Self, label: []const u8) !void { pub fn add_item(self: *Self, label: []const u8) !void {
try self.menu.add(try Button.create(*Self, self.a, self.menu.parent, .{ try self.menu.add(try Button.create(*Self, self.allocator, self.menu.parent, .{
.ctx = self, .ctx = self,
.on_layout = self.opts.on_layout, .on_layout = self.opts.on_layout,
.label = label, .label = label,
@ -111,7 +111,7 @@ pub fn State(ctx_type: type) type {
} }
pub fn add_item_with_handler(self: *Self, label: []const u8, on_click: *const fn (_: **Self, _: *Button.State(*Self)) void) !void { pub fn add_item_with_handler(self: *Self, label: []const u8, on_click: *const fn (_: **Self, _: *Button.State(*Self)) void) !void {
try self.menu.add(try Button.create_widget(*Self, self.a, self.menu.parent, .{ try self.menu.add(try Button.create_widget(*Self, self.allocator, self.menu.parent, .{
.ctx = self, .ctx = self,
.on_layout = on_layout, .on_layout = on_layout,
.label = label, .label = label,
@ -125,7 +125,7 @@ pub fn State(ctx_type: type) type {
pub fn reset_items(self: *Self) void { pub fn reset_items(self: *Self) void {
for (self.menu.widgets.items, 0..) |*w, i| for (self.menu.widgets.items, 0..) |*w, i|
if (i >= self.header_count) if (i >= self.header_count)
w.widget.deinit(self.a); w.widget.deinit(self.allocator);
self.menu.widgets.shrinkRetainingCapacity(self.header_count); self.menu.widgets.shrinkRetainingCapacity(self.header_count);
} }

View file

@ -89,13 +89,13 @@ pub fn filter(self: Self, from_: tp.pid_ref, m: tp.message) error{Exit}!bool {
} }
pub const List = struct { pub const List = struct {
a: Allocator, allocator: Allocator,
list: ArrayList(MessageFilter), list: ArrayList(MessageFilter),
pub fn init(a: Allocator) List { pub fn init(allocator: Allocator) List {
return .{ return .{
.a = a, .allocator = allocator,
.list = ArrayList(MessageFilter).init(a), .list = ArrayList(MessageFilter).init(allocator),
}; };
} }
@ -121,7 +121,7 @@ pub const List = struct {
} }
pub fn filter(self: *const List, from: tp.pid_ref, m: tp.message) error{Exit}!bool { pub fn filter(self: *const List, from: tp.pid_ref, m: tp.message) error{Exit}!bool {
var sfa = std.heap.stackFallback(4096, self.a); var sfa = std.heap.stackFallback(4096, self.allocator);
const a = sfa.get(); const a = sfa.get();
const buf = a.alloc(u8, m.buf.len) catch |e| return tp.exit_error(e, @errorReturnTrace()); const buf = a.alloc(u8, m.buf.len) catch |e| return tp.exit_error(e, @errorReturnTrace());
defer a.free(buf); defer a.free(buf);

View file

@ -39,7 +39,7 @@ pub const Layout = union(enum) {
}; };
pub const VTable = struct { pub const VTable = struct {
deinit: *const fn (ctx: *anyopaque, a: Allocator) void, deinit: *const fn (ctx: *anyopaque, allocator: Allocator) void,
send: *const fn (ctx: *anyopaque, from: tp.pid_ref, m: tp.message) error{Exit}!bool, send: *const fn (ctx: *anyopaque, from: tp.pid_ref, m: tp.message) error{Exit}!bool,
update: *const fn (ctx: *anyopaque) void, update: *const fn (ctx: *anyopaque) void,
render: *const fn (ctx: *anyopaque, theme: *const Theme) bool, render: *const fn (ctx: *anyopaque, theme: *const Theme) bool,
@ -62,8 +62,8 @@ pub fn to(pimpl: anytype) Self {
.vtable = comptime &.{ .vtable = comptime &.{
.type_name = @typeName(child), .type_name = @typeName(child),
.deinit = struct { .deinit = struct {
pub fn deinit(ctx: *anyopaque, a: Allocator) void { pub fn deinit(ctx: *anyopaque, allocator: Allocator) void {
return child.deinit(@as(*child, @ptrCast(@alignCast(ctx))), a); return child.deinit(@as(*child, @ptrCast(@alignCast(ctx))), allocator);
} }
}.deinit, }.deinit,
.send = if (@hasDecl(child, "receive")) struct { .send = if (@hasDecl(child, "receive")) struct {
@ -169,8 +169,8 @@ pub fn box(self: Self) Box {
return Box.from(self.plane.*); return Box.from(self.plane.*);
} }
pub fn deinit(self: Self, a: Allocator) void { pub fn deinit(self: Self, allocator: Allocator) void {
return self.vtable.deinit(self.ptr, a); return self.vtable.deinit(self.ptr, allocator);
} }
pub fn msg(self: *const Self, m: anytype) error{Exit}!bool { pub fn msg(self: *const Self, m: anytype) error{Exit}!bool {
@ -221,9 +221,9 @@ pub fn hover(self: *Self) bool {
return self.vtable.hover(self.ptr); return self.vtable.hover(self.ptr);
} }
pub fn empty(a: Allocator, parent: Plane, layout_: Layout) !Self { pub fn empty(allocator: Allocator, parent: Plane, layout_: Layout) !Self {
const child: type = struct { plane: Plane, layout: Layout }; const child: type = struct { plane: Plane, layout: Layout };
const widget = try a.create(child); const widget = try allocator.create(child);
const n = try Plane.init(&(Box{}).opts("empty"), parent); const n = try Plane.init(&(Box{}).opts("empty"), parent);
widget.* = .{ .plane = n, .layout = layout_ }; widget.* = .{ .plane = n, .layout = layout_ };
return .{ return .{
@ -232,10 +232,10 @@ pub fn empty(a: Allocator, parent: Plane, layout_: Layout) !Self {
.vtable = comptime &.{ .vtable = comptime &.{
.type_name = @typeName(child), .type_name = @typeName(child),
.deinit = struct { .deinit = struct {
pub fn deinit(ctx: *anyopaque, a_: Allocator) void { pub fn deinit(ctx: *anyopaque, allocator_: Allocator) void {
const self: *child = @ptrCast(@alignCast(ctx)); const self: *child = @ptrCast(@alignCast(ctx));
self.plane.deinit(); self.plane.deinit();
a_.destroy(self); allocator_.destroy(self);
} }
}.deinit, }.deinit,
.send = struct { .send = struct {

View file

@ -21,7 +21,7 @@ const WidgetState = struct {
plane: Plane, plane: Plane,
parent: Plane, parent: Plane,
a: Allocator, allocator: Allocator,
widgets: ArrayList(WidgetState), widgets: ArrayList(WidgetState),
layout: Layout, layout: Layout,
direction: Direction, direction: Direction,
@ -31,33 +31,33 @@ on_render: *const fn (ctx: ?*anyopaque, theme: *const Widget.Theme) void = on_re
after_render: *const fn (ctx: ?*anyopaque, theme: *const Widget.Theme) void = on_render_default, after_render: *const fn (ctx: ?*anyopaque, theme: *const Widget.Theme) void = on_render_default,
on_resize: *const fn (ctx: ?*anyopaque, self: *Self, pos_: Widget.Box) void = on_resize_default, on_resize: *const fn (ctx: ?*anyopaque, self: *Self, pos_: Widget.Box) void = on_resize_default,
pub fn createH(a: Allocator, parent: Widget, name: [:0]const u8, layout_: Layout) !*Self { pub fn createH(allocator: Allocator, parent: Widget, name: [:0]const u8, layout_: Layout) !*Self {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = try init(a, parent, name, .horizontal, layout_, Box{}); self.* = try init(allocator, parent, name, .horizontal, layout_, Box{});
self.plane.hide(); self.plane.hide();
return self; return self;
} }
pub fn createV(a: Allocator, parent: Widget, name: [:0]const u8, layout_: Layout) !*Self { pub fn createV(allocator: Allocator, parent: Widget, name: [:0]const u8, layout_: Layout) !*Self {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = try init(a, parent, name, .vertical, layout_, Box{}); self.* = try init(allocator, parent, name, .vertical, layout_, Box{});
self.plane.hide(); self.plane.hide();
return self; return self;
} }
pub fn createBox(a: Allocator, parent: Widget, name: [:0]const u8, dir: Direction, layout_: Layout, box: Box) !*Self { pub fn createBox(allocator: Allocator, parent: Widget, name: [:0]const u8, dir: Direction, layout_: Layout, box: Box) !*Self {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = try init(a, parent, name, dir, layout_, box); self.* = try init(allocator, parent, name, dir, layout_, box);
self.plane.hide(); self.plane.hide();
return self; return self;
} }
fn init(a: Allocator, parent: Widget, name: [:0]const u8, dir: Direction, layout_: Layout, box: Box) !Self { fn init(allocator: Allocator, parent: Widget, name: [:0]const u8, dir: Direction, layout_: Layout, box: Box) !Self {
return .{ return .{
.plane = try Plane.init(&box.opts(name), parent.plane.*), .plane = try Plane.init(&box.opts(name), parent.plane.*),
.parent = parent.plane.*, .parent = parent.plane.*,
.a = a, .allocator = allocator,
.widgets = ArrayList(WidgetState).init(a), .widgets = ArrayList(WidgetState).init(allocator),
.layout = layout_, .layout = layout_,
.direction = dir, .direction = dir,
}; };
@ -71,12 +71,12 @@ pub fn layout(self: *Self) Widget.Layout {
return self.layout; return self.layout;
} }
pub fn deinit(self: *Self, a: std.mem.Allocator) void { pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
for (self.widgets.items) |*w| for (self.widgets.items) |*w|
w.widget.deinit(self.a); w.widget.deinit(self.allocator);
self.widgets.deinit(); self.widgets.deinit();
self.plane.deinit(); self.plane.deinit();
a.destroy(self); allocator.destroy(self);
} }
pub fn add(self: *Self, w_: Widget) !void { pub fn add(self: *Self, w_: Widget) !void {
@ -92,7 +92,7 @@ pub fn addP(self: *Self, w_: Widget) !*Widget {
pub fn remove(self: *Self, w: Widget) void { pub fn remove(self: *Self, w: Widget) void {
for (self.widgets.items, 0..) |p, i| if (p.widget.ptr == w.ptr) for (self.widgets.items, 0..) |p, i| if (p.widget.ptr == w.ptr)
self.widgets.orderedRemove(i).widget.deinit(self.a); self.widgets.orderedRemove(i).widget.deinit(self.allocator);
} }
pub fn empty(self: *const Self) bool { pub fn empty(self: *const Self) bool {
@ -108,7 +108,7 @@ pub fn swap(self: *Self, n: usize, w: Widget) Widget {
pub fn replace(self: *Self, n: usize, w: Widget) void { pub fn replace(self: *Self, n: usize, w: Widget) void {
const old = self.swap(n, w); const old = self.swap(n, w);
old.deinit(self.a); old.deinit(self.allocator);
} }
pub fn send(self: *Self, from: tp.pid_ref, m: tp.message) error{Exit}!bool { pub fn send(self: *Self, from: tp.pid_ref, m: tp.message) error{Exit}!bool {

View file

@ -8,19 +8,19 @@ const Widget = @import("Widget.zig");
const Self = @This(); const Self = @This();
a: Allocator, allocator: Allocator,
widgets: ArrayList(Widget), widgets: ArrayList(Widget),
pub fn init(a_: Allocator) Self { pub fn init(allocator: Allocator) Self {
return .{ return .{
.a = a_, .allocator = allocator,
.widgets = ArrayList(Widget).init(a_), .widgets = ArrayList(Widget).init(allocator),
}; };
} }
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
for (self.widgets.items) |*widget| for (self.widgets.items) |*widget|
widget.deinit(self.a); widget.deinit(self.allocator);
self.widgets.deinit(); self.widgets.deinit();
} }
@ -41,7 +41,7 @@ pub fn replace(self: *Self, n: usize, widget: Widget) void {
pub fn remove(self: *Self, w: Widget) void { pub fn remove(self: *Self, w: Widget) void {
for (self.widgets.items, 0..) |p, i| if (p.ptr == w.ptr) for (self.widgets.items, 0..) |p, i| if (p.ptr == w.ptr)
self.widgets.orderedRemove(i).deinit(self.a); self.widgets.orderedRemove(i).deinit(self.allocator);
} }
pub fn delete(self: *Self, name: []const u8) bool { pub fn delete(self: *Self, name: []const u8) bool {

File diff suppressed because it is too large Load diff

View file

@ -19,7 +19,7 @@ const tui = @import("tui.zig");
const command = @import("command.zig"); const command = @import("command.zig");
const ed = @import("editor.zig"); const ed = @import("editor.zig");
a: Allocator, allocator: Allocator,
plane: Plane, plane: Plane,
parent: Widget, parent: Widget,
@ -40,10 +40,10 @@ const Self = @This();
const Kind = enum { insert, modified, delete }; const Kind = enum { insert, modified, delete };
const Symbol = struct { kind: Kind, line: usize }; const Symbol = struct { kind: Kind, line: usize };
pub fn create(a: Allocator, parent: Widget, event_source: Widget, editor: *ed.Editor) !Widget { pub fn create(allocator: Allocator, parent: Widget, event_source: Widget, editor: *ed.Editor) !Widget {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent.plane.*), .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent.plane.*),
.parent = parent, .parent = parent,
.linenum = tui.current().config.gutter_line_numbers, .linenum = tui.current().config.gutter_line_numbers,
@ -51,7 +51,7 @@ pub fn create(a: Allocator, parent: Widget, event_source: Widget, editor: *ed.Ed
.highlight = tui.current().config.highlight_current_line_gutter, .highlight = tui.current().config.highlight_current_line_gutter,
.editor = editor, .editor = editor,
.diff = try diff.create(), .diff = try diff.create(),
.diff_symbols = std.ArrayList(Symbol).init(a), .diff_symbols = std.ArrayList(Symbol).init(allocator),
}; };
try tui.current().message_filters.add(MessageFilter.bind(self, filter_receive)); try tui.current().message_filters.add(MessageFilter.bind(self, filter_receive));
try event_source.subscribe(EventHandler.bind(self, handle_event)); try event_source.subscribe(EventHandler.bind(self, handle_event));
@ -62,12 +62,12 @@ pub fn widget(self: *Self) Widget {
return Widget.to(self); return Widget.to(self);
} }
pub fn deinit(self: *Self, a: Allocator) void { pub fn deinit(self: *Self, allocator: Allocator) void {
self.diff_symbols_clear(); self.diff_symbols_clear();
self.diff_symbols.deinit(); self.diff_symbols.deinit();
tui.current().message_filters.remove_ptr(self); tui.current().message_filters.remove_ptr(self);
self.plane.deinit(); self.plane.deinit();
a.destroy(self); allocator.destroy(self);
} }
fn diff_symbols_clear(self: *Self) void { fn diff_symbols_clear(self: *Self) void {

View file

@ -76,10 +76,10 @@ pub fn create(allocator: Allocator, parent: Plane) !Widget {
return Widget.to(self); return Widget.to(self);
} }
pub fn deinit(self: *Self, a: Allocator) void { pub fn deinit(self: *Self, allocator: Allocator) void {
self.plane.deinit(); self.plane.deinit();
self.commands.deinit(); self.commands.deinit();
a.destroy(self); allocator.destroy(self);
} }
fn scrollbar_style(sb: *scrollbar_v, theme: *const Widget.Theme) Widget.Theme.Style { fn scrollbar_style(sb: *scrollbar_v, theme: *const Widget.Theme) Widget.Theme.Style {

View file

@ -15,7 +15,7 @@ const tui = @import("tui.zig");
const command = @import("command.zig"); const command = @import("command.zig");
const fonts = @import("fonts.zig"); const fonts = @import("fonts.zig");
a: std.mem.Allocator, allocator: std.mem.Allocator,
plane: Plane, plane: Plane,
parent: Plane, parent: Plane,
fire: ?Fire = null, fire: ?Fire = null,
@ -24,17 +24,17 @@ menu: *Menu.State(*Self),
const Self = @This(); const Self = @This();
pub fn create(a: std.mem.Allocator, parent: Widget) !Widget { pub fn create(allocator: std.mem.Allocator, parent: Widget) !Widget {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
var n = try Plane.init(&(Widget.Box{}).opts("editor"), parent.plane.*); var n = try Plane.init(&(Widget.Box{}).opts("editor"), parent.plane.*);
errdefer n.deinit(); errdefer n.deinit();
const w = Widget.to(self); const w = Widget.to(self);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.parent = parent.plane.*, .parent = parent.plane.*,
.plane = n, .plane = n,
.menu = try Menu.create(*Self, a, w, .{ .ctx = self, .on_render = menu_on_render }), .menu = try Menu.create(*Self, allocator, w, .{ .ctx = self, .on_render = menu_on_render }),
}; };
try self.commands.init(self); try self.commands.init(self);
try self.menu.add_item_with_handler("Help ······················· :h", menu_action_help); try self.menu.add_item_with_handler("Help ······················· :h", menu_action_help);
@ -50,12 +50,12 @@ pub fn create(a: std.mem.Allocator, parent: Widget) !Widget {
return w; return w;
} }
pub fn deinit(self: *Self, a: std.mem.Allocator) void { pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
self.menu.deinit(a); self.menu.deinit(allocator);
self.commands.deinit(); self.commands.deinit();
self.plane.deinit(); self.plane.deinit();
if (self.fire) |*fire| fire.deinit(); if (self.fire) |*fire| fire.deinit();
a.destroy(self); allocator.destroy(self);
} }
pub fn update(self: *Self) void { pub fn update(self: *Self) void {
@ -186,7 +186,7 @@ pub fn handle_resize(self: *Self, pos: Widget.Box) void {
self.plane.resize_simple(@intCast(pos.h), @intCast(pos.w)) catch return; self.plane.resize_simple(@intCast(pos.h), @intCast(pos.w)) catch return;
if (self.fire) |*fire| { if (self.fire) |*fire| {
fire.deinit(); fire.deinit();
self.fire = Fire.init(self.a, self.plane) catch return; self.fire = Fire.init(self.allocator, self.plane) catch return;
} }
} }
@ -213,7 +213,7 @@ const cmds = struct {
self.fire = if (self.fire) |*fire| ret: { self.fire = if (self.fire) |*fire| ret: {
fire.deinit(); fire.deinit();
break :ret null; break :ret null;
} else try Fire.init(self.a, self.plane); } else try Fire.init(self.allocator, self.plane);
} }
}; };
@ -239,12 +239,12 @@ const Fire = struct {
const MAX_COLOR = 256; const MAX_COLOR = 256;
const LAST_COLOR = MAX_COLOR - 1; const LAST_COLOR = MAX_COLOR - 1;
fn init(a: std.mem.Allocator, plane: Plane) !Fire { fn init(allocator: std.mem.Allocator, plane: Plane) !Fire {
const pos = Widget.Box.from(plane); const pos = Widget.Box.from(plane);
const FIRE_H = @as(u16, @intCast(pos.h)) * 2; const FIRE_H = @as(u16, @intCast(pos.h)) * 2;
const FIRE_W = @as(u16, @intCast(pos.w)); const FIRE_W = @as(u16, @intCast(pos.w));
var self: Fire = .{ var self: Fire = .{
.allocator = a, .allocator = allocator,
.plane = plane, .plane = plane,
.prng = std.Random.DefaultPrng.init(blk: { .prng = std.Random.DefaultPrng.init(blk: {
var seed: u64 = undefined; var seed: u64 = undefined;
@ -255,7 +255,7 @@ const Fire = struct {
.FIRE_W = FIRE_W, .FIRE_W = FIRE_W,
.FIRE_SZ = FIRE_H * FIRE_W, .FIRE_SZ = FIRE_H * FIRE_W,
.FIRE_LAST_ROW = (FIRE_H - 1) * FIRE_W, .FIRE_LAST_ROW = (FIRE_H - 1) * FIRE_W,
.screen_buf = try a.alloc(u8, FIRE_H * FIRE_W), .screen_buf = try allocator.alloc(u8, FIRE_H * FIRE_W),
}; };
var buf_idx: u16 = 0; var buf_idx: u16 = 0;

View file

@ -15,7 +15,7 @@ const EventHandler = @import("EventHandler.zig");
pub const name = "inputview"; pub const name = "inputview";
a: Allocator, allocator: Allocator,
parent: Plane, parent: Plane,
plane: Plane, plane: Plane,
last_count: u64 = 0, last_count: u64 = 0,
@ -30,27 +30,27 @@ const Entry = struct {
}; };
const Buffer = ArrayList(Entry); const Buffer = ArrayList(Entry);
pub fn create(a: Allocator, parent: Plane) !Widget { pub fn create(allocator: Allocator, parent: Plane) !Widget {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
var n = try Plane.init(&(Widget.Box{}).opts_vscroll(@typeName(Self)), parent); var n = try Plane.init(&(Widget.Box{}).opts_vscroll(@typeName(Self)), parent);
errdefer n.deinit(); errdefer n.deinit();
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.parent = parent, .parent = parent,
.plane = n, .plane = n,
.buffer = Buffer.init(a), .buffer = Buffer.init(allocator),
}; };
try tui.current().input_listeners.add(EventHandler.bind(self, listen)); try tui.current().input_listeners.add(EventHandler.bind(self, listen));
return Widget.to(self); return Widget.to(self);
} }
pub fn deinit(self: *Self, a: Allocator) void { pub fn deinit(self: *Self, allocator: Allocator) void {
tui.current().input_listeners.remove_ptr(self); tui.current().input_listeners.remove_ptr(self);
for (self.buffer.items) |item| for (self.buffer.items) |item|
self.buffer.allocator.free(item.json); self.buffer.allocator.free(item.json);
self.buffer.deinit(); self.buffer.deinit();
self.plane.deinit(); self.plane.deinit();
a.destroy(self); allocator.destroy(self);
} }
pub fn render(self: *Self, theme: *const Widget.Theme) bool { pub fn render(self: *Self, theme: *const Widget.Theme) bool {
@ -96,7 +96,7 @@ fn append(self: *Self, json: []const u8) !void {
(try self.buffer.addOne()).* = .{ (try self.buffer.addOne()).* = .{
.time = ts, .time = ts,
.tdiff = tdiff, .tdiff = tdiff,
.json = try self.a.dupeZ(u8, json), .json = try self.allocator.dupeZ(u8, json),
}; };
} }

View file

@ -27,13 +27,13 @@ last_node: usize = 0,
const Self = @This(); const Self = @This();
pub fn create(a: Allocator, parent: Plane) !Widget { pub fn create(allocator: Allocator, parent: Plane) !Widget {
if (tui.current().mainview.dynamic_cast(mainview)) |mv_| if (mv_.get_editor()) |editor| { if (tui.current().mainview.dynamic_cast(mainview)) |mv_| if (mv_.get_editor()) |editor| {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.plane = try Plane.init(&(Widget.Box{}).opts_vscroll(name), parent), .plane = try Plane.init(&(Widget.Box{}).opts_vscroll(name), parent),
.editor = editor, .editor = editor,
.pos_cache = try ed.PosToWidthCache.init(a), .pos_cache = try ed.PosToWidthCache.init(allocator),
}; };
try editor.handlers.add(EventHandler.bind(self, ed_receive)); try editor.handlers.add(EventHandler.bind(self, ed_receive));
@ -42,11 +42,11 @@ pub fn create(a: Allocator, parent: Plane) !Widget {
return error.NotFound; return error.NotFound;
} }
pub fn deinit(self: *Self, a: Allocator) void { pub fn deinit(self: *Self, allocator: Allocator) void {
self.editor.handlers.remove_ptr(self); self.editor.handlers.remove_ptr(self);
tui.current().message_filters.remove_ptr(self); tui.current().message_filters.remove_ptr(self);
self.plane.deinit(); self.plane.deinit();
a.destroy(self); allocator.destroy(self);
} }
pub fn render(self: *Self, theme: *const Widget.Theme) bool { pub fn render(self: *Self, theme: *const Widget.Theme) bool {

View file

@ -39,15 +39,15 @@ const Level = enum {
err, err,
}; };
pub fn create(a: Allocator, parent: Plane) !Widget { pub fn create(allocator: Allocator, parent: Plane) !Widget {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ .plane = try Plane.init(&(Widget.Box{}).opts(name), parent) }; self.* = .{ .plane = try Plane.init(&(Widget.Box{}).opts(name), parent) };
return Widget.to(self); return Widget.to(self);
} }
pub fn deinit(self: *Self, a: Allocator) void { pub fn deinit(self: *Self, allocator: Allocator) void {
self.plane.deinit(); self.plane.deinit();
a.destroy(self); allocator.destroy(self);
} }
pub fn render(self: *Self, theme: *const Widget.Theme) bool { pub fn render(self: *Self, theme: *const Widget.Theme) bool {
@ -140,7 +140,7 @@ fn get_buffer() *Buffer {
return if (persistent_buffer) |*p| p else @panic("logview.get_buffer called before init"); return if (persistent_buffer) |*p| p else @panic("logview.get_buffer called before init");
} }
pub fn init(a: Allocator) void { pub fn init(allocator: Allocator) void {
if (persistent_buffer) |_| return; if (persistent_buffer) |_| return;
persistent_buffer = Buffer.init(a); persistent_buffer = Buffer.init(allocator);
} }

View file

@ -28,7 +28,7 @@ const filelist_view = @import("filelist_view.zig");
const Self = @This(); const Self = @This();
const Commands = command.Collection(cmds); const Commands = command.Collection(cmds);
a: std.mem.Allocator, allocator: std.mem.Allocator,
plane: Plane, plane: Plane,
widgets: *WidgetList, widgets: *WidgetList,
widgets_widget: Widget, widgets_widget: Widget,
@ -61,30 +61,30 @@ const FileListType = enum {
find_in_files, find_in_files,
}; };
pub fn create(a: std.mem.Allocator) !Widget { pub fn create(allocator: std.mem.Allocator) !Widget {
const self = try a.create(Self); const self = try allocator.create(Self);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.plane = tui.current().stdplane(), .plane = tui.current().stdplane(),
.widgets = undefined, .widgets = undefined,
.widgets_widget = undefined, .widgets_widget = undefined,
.floating_views = WidgetStack.init(a), .floating_views = WidgetStack.init(allocator),
.location_history = try location_history.create(), .location_history = try location_history.create(),
.file_stack = std.ArrayList([]const u8).init(a), .file_stack = std.ArrayList([]const u8).init(allocator),
.view_widget_idx = 0, .view_widget_idx = 0,
}; };
try self.commands.init(self); try self.commands.init(self);
const w = Widget.to(self); const w = Widget.to(self);
const widgets = try WidgetList.createV(a, w, @typeName(Self), .dynamic); const widgets = try WidgetList.createV(allocator, w, @typeName(Self), .dynamic);
self.widgets = widgets; self.widgets = widgets;
self.widgets_widget = widgets.widget(); self.widgets_widget = widgets.widget();
if (tui.current().config.top_bar.len > 0) { if (tui.current().config.top_bar.len > 0) {
self.top_bar = try widgets.addP(try @import("status/bar.zig").create(a, w, tui.current().config.top_bar, .none, null)); self.top_bar = try widgets.addP(try @import("status/bar.zig").create(allocator, w, tui.current().config.top_bar, .none, null));
self.view_widget_idx += 1; self.view_widget_idx += 1;
} }
try widgets.add(try Widget.empty(a, self.widgets_widget.plane.*, .dynamic)); try widgets.add(try Widget.empty(allocator, self.widgets_widget.plane.*, .dynamic));
if (tui.current().config.bottom_bar.len > 0) { if (tui.current().config.bottom_bar.len > 0) {
self.bottom_bar = try widgets.addP(try @import("status/bar.zig").create(a, w, tui.current().config.bottom_bar, .grip, EventHandler.bind(self, handle_bottom_bar_event))); self.bottom_bar = try widgets.addP(try @import("status/bar.zig").create(allocator, w, tui.current().config.bottom_bar, .grip, EventHandler.bind(self, handle_bottom_bar_event)));
} }
if (tp.env.get().is("show-input")) if (tp.env.get().is("show-input"))
self.toggle_inputview_async(); self.toggle_inputview_async();
@ -93,14 +93,14 @@ pub fn create(a: std.mem.Allocator) !Widget {
return w; return w;
} }
pub fn deinit(self: *Self, a: std.mem.Allocator) void { pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
self.close_all_panel_views(); self.close_all_panel_views();
self.clear_file_stack(); self.clear_file_stack();
self.file_stack.deinit(); self.file_stack.deinit();
self.commands.deinit(); self.commands.deinit();
self.widgets.deinit(a); self.widgets.deinit(allocator);
self.floating_views.deinit(); self.floating_views.deinit();
a.destroy(self); allocator.destroy(self);
} }
pub fn receive(self: *Self, from_: tp.pid_ref, m: tp.message) error{Exit}!bool { pub fn receive(self: *Self, from_: tp.pid_ref, m: tp.message) error{Exit}!bool {
@ -180,12 +180,12 @@ fn toggle_panel_view(self: *Self, view: anytype, enable_only: bool) !void {
} }
} }
} else { } else {
try panels.add(try view.create(self.a, self.widgets.plane)); try panels.add(try view.create(self.allocator, self.widgets.plane));
} }
} else { } else {
const panels = try WidgetList.createH(self.a, self.widgets.widget(), "panel", .{ .static = self.panel_height orelse self.box().h / 5 }); const panels = try WidgetList.createH(self.allocator, self.widgets.widget(), "panel", .{ .static = self.panel_height orelse self.box().h / 5 });
try self.widgets.add(panels.widget()); try self.widgets.add(panels.widget());
try panels.add(try view.create(self.a, self.widgets.plane)); try panels.add(try view.create(self.allocator, self.widgets.plane));
self.panels = panels; self.panels = panels;
} }
tui.current().resize(); tui.current().resize();
@ -211,7 +211,7 @@ fn toggle_view(self: *Self, view: anytype) !void {
if (self.widgets.get(@typeName(view))) |w| { if (self.widgets.get(@typeName(view))) |w| {
self.widgets.remove(w.*); self.widgets.remove(w.*);
} else { } else {
try self.widgets.add(try view.create(self.a, self.plane)); try self.widgets.add(try view.create(self.allocator, self.plane));
} }
tui.current().resize(); tui.current().resize();
} }
@ -269,8 +269,8 @@ const cmds = struct {
tui.current().rdr.set_terminal_working_directory(project); tui.current().rdr.set_terminal_working_directory(project);
if (self.top_bar) |bar| _ = try bar.msg(.{ "PRJ", "open" }); if (self.top_bar) |bar| _ = try bar.msg(.{ "PRJ", "open" });
if (self.bottom_bar) |bar| _ = try bar.msg(.{ "PRJ", "open" }); if (self.bottom_bar) |bar| _ = try bar.msg(.{ "PRJ", "open" });
if (try project_manager.request_most_recent_file(self.a)) |file_path| { if (try project_manager.request_most_recent_file(self.allocator)) |file_path| {
defer self.a.free(file_path); defer self.allocator.free(file_path);
try tp.self_pid().send(.{ "cmd", "navigate", .{ .file = file_path } }); try tp.self_pid().send(.{ "cmd", "navigate", .{ .file = file_path } });
} }
} }
@ -523,7 +523,7 @@ pub fn handle_editor_event(self: *Self, _: tp.pid_ref, m: tp.message) tp.result
if (try m.match(.{ "E", "close" })) { if (try m.match(.{ "E", "close" })) {
if (self.pop_file_stack(editor.file_path)) |file_path| { if (self.pop_file_stack(editor.file_path)) |file_path| {
defer self.a.free(file_path); defer self.allocator.free(file_path);
self.show_previous_async(file_path); self.show_previous_async(file_path);
} else self.show_home_async(); } else self.show_home_async();
self.editor = null; self.editor = null;
@ -537,7 +537,7 @@ pub fn handle_editor_event(self: *Self, _: tp.pid_ref, m: tp.message) tp.result
sel.normalize(); sel.normalize();
if (sel.end.row - sel.begin.row > ed.max_match_lines) if (sel.end.row - sel.begin.row > ed.max_match_lines)
return self.clear_auto_find(editor); return self.clear_auto_find(editor);
const text = editor.get_selection(sel, self.a) catch return self.clear_auto_find(editor); const text = editor.get_selection(sel, self.allocator) catch return self.clear_auto_find(editor);
if (text.len == 0) if (text.len == 0)
return self.clear_auto_find(editor); return self.clear_auto_find(editor);
if (!self.is_last_match_text(text)) { if (!self.is_last_match_text(text)) {
@ -552,7 +552,7 @@ pub fn find_in_files(self: *Self, query: []const u8) !void {
log.logger("find").print("finding files...", .{}); log.logger("find").print("finding files...", .{});
const find_f = ripgrep.find_in_files; const find_f = ripgrep.find_in_files;
if (std.mem.indexOfScalar(u8, query, '\n')) |_| return; if (std.mem.indexOfScalar(u8, query, '\n')) |_| return;
var rg = try find_f(self.a, query, "FIF"); var rg = try find_f(self.allocator, query, "FIF");
defer rg.deinit(); defer rg.deinit();
} }
@ -600,7 +600,7 @@ fn is_last_match_text(self: *Self, text: []const u8) bool {
fn store_last_match_text(self: *Self, text: ?[]const u8) void { fn store_last_match_text(self: *Self, text: ?[]const u8) void {
if (self.last_match_text) |old| if (self.last_match_text) |old|
self.a.free(old); self.allocator.free(old);
self.last_match_text = text; self.last_match_text = text;
} }
@ -614,10 +614,10 @@ pub fn walk(self: *Self, ctx: *anyopaque, f: Widget.WalkFn, w: *Widget) bool {
fn create_editor(self: *Self) !void { fn create_editor(self: *Self) !void {
if (self.editor) |editor| if (editor.file_path) |file_path| self.push_file_stack(file_path) catch {}; if (self.editor) |editor| if (editor.file_path) |file_path| self.push_file_stack(file_path) catch {};
self.widgets.replace(self.view_widget_idx, try Widget.empty(self.a, self.plane, .dynamic)); self.widgets.replace(self.view_widget_idx, try Widget.empty(self.allocator, self.plane, .dynamic));
command.executeName("enter_mode_default", .{}) catch {}; command.executeName("enter_mode_default", .{}) catch {};
var editor_widget = try ed.create(self.a, Widget.to(self)); var editor_widget = try ed.create(self.allocator, Widget.to(self));
errdefer editor_widget.deinit(self.a); errdefer editor_widget.deinit(self.allocator);
if (editor_widget.get("editor")) |editor| { if (editor_widget.get("editor")) |editor| {
if (self.top_bar) |bar| editor.subscribe(EventHandler.to_unowned(bar)) catch @panic("subscribe unsupported"); if (self.top_bar) |bar| editor.subscribe(EventHandler.to_unowned(bar)) catch @panic("subscribe unsupported");
if (self.bottom_bar) |bar| editor.subscribe(EventHandler.to_unowned(bar)) catch @panic("subscribe unsupported"); if (self.bottom_bar) |bar| editor.subscribe(EventHandler.to_unowned(bar)) catch @panic("subscribe unsupported");
@ -647,15 +647,15 @@ fn show_home_async(_: *Self) void {
fn create_home(self: *Self) !void { fn create_home(self: *Self) !void {
tui.reset_drag_context(); tui.reset_drag_context();
if (self.editor) |_| return; if (self.editor) |_| return;
var home_widget = try home.create(self.a, Widget.to(self)); var home_widget = try home.create(self.allocator, Widget.to(self));
errdefer home_widget.deinit(self.a); errdefer home_widget.deinit(self.allocator);
self.widgets.replace(self.view_widget_idx, home_widget); self.widgets.replace(self.view_widget_idx, home_widget);
tui.current().resize(); tui.current().resize();
} }
fn write_restore_info(self: *Self) void { fn write_restore_info(self: *Self) void {
if (self.editor) |editor| { if (self.editor) |editor| {
var sfa = std.heap.stackFallback(512, self.a); var sfa = std.heap.stackFallback(512, self.allocator);
const a = sfa.get(); const a = sfa.get();
var meta = std.ArrayList(u8).init(a); var meta = std.ArrayList(u8).init(a);
editor.write_state(meta.writer()) catch return; editor.write_state(meta.writer()) catch return;
@ -672,8 +672,8 @@ fn read_restore_info(self: *Self) !void {
const file = try std.fs.cwd().openFile(file_name, .{ .mode = .read_only }); const file = try std.fs.cwd().openFile(file_name, .{ .mode = .read_only });
defer file.close(); defer file.close();
const stat = try file.stat(); const stat = try file.stat();
var buf = try self.a.alloc(u8, @intCast(stat.size)); var buf = try self.allocator.alloc(u8, @intCast(stat.size));
defer self.a.free(buf); defer self.allocator.free(buf);
const size = try file.readAll(buf); const size = try file.readAll(buf);
try editor.extract_state(buf[0..size]); try editor.extract_state(buf[0..size]);
} }
@ -682,20 +682,20 @@ fn read_restore_info(self: *Self) !void {
fn push_file_stack(self: *Self, file_path: []const u8) !void { fn push_file_stack(self: *Self, file_path: []const u8) !void {
for (self.file_stack.items, 0..) |file_path_, i| for (self.file_stack.items, 0..) |file_path_, i|
if (std.mem.eql(u8, file_path, file_path_)) if (std.mem.eql(u8, file_path, file_path_))
self.a.free(self.file_stack.orderedRemove(i)); self.allocator.free(self.file_stack.orderedRemove(i));
(try self.file_stack.addOne()).* = try self.a.dupe(u8, file_path); (try self.file_stack.addOne()).* = try self.allocator.dupe(u8, file_path);
} }
fn pop_file_stack(self: *Self, closed: ?[]const u8) ?[]const u8 { fn pop_file_stack(self: *Self, closed: ?[]const u8) ?[]const u8 {
if (closed) |file_path| if (closed) |file_path|
for (self.file_stack.items, 0..) |file_path_, i| for (self.file_stack.items, 0..) |file_path_, i|
if (std.mem.eql(u8, file_path, file_path_)) if (std.mem.eql(u8, file_path, file_path_))
self.a.free(self.file_stack.orderedRemove(i)); self.allocator.free(self.file_stack.orderedRemove(i));
return self.file_stack.popOrNull(); return self.file_stack.popOrNull();
} }
fn clear_file_stack(self: *Self) void { fn clear_file_stack(self: *Self) void {
for (self.file_stack.items) |file_path| self.a.free(file_path); for (self.file_stack.items) |file_path| self.allocator.free(file_path);
self.file_stack.clearRetainingCapacity(); self.file_stack.clearRetainingCapacity();
} }

View file

@ -18,16 +18,16 @@ const eql = @import("std").mem.eql;
const Self = @This(); const Self = @This();
const input_buffer_size = 1024; const input_buffer_size = 1024;
a: Allocator, allocator: Allocator,
input: ArrayList(u8), input: ArrayList(u8),
last_cmd: []const u8 = "", last_cmd: []const u8 = "",
leader: ?struct { keypress: u32, modifiers: u32 } = null, leader: ?struct { keypress: u32, modifiers: u32 } = null,
pub fn create(a: Allocator) !tui.Mode { pub fn create(allocator: Allocator) !tui.Mode {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.input = try ArrayList(u8).initCapacity(a, input_buffer_size), .input = try ArrayList(u8).initCapacity(allocator, input_buffer_size),
}; };
return .{ return .{
.handler = EventHandler.to_owned(self), .handler = EventHandler.to_owned(self),
@ -39,7 +39,7 @@ pub fn create(a: Allocator) !tui.Mode {
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
self.input.deinit(); self.input.deinit();
self.a.destroy(self); self.allocator.destroy(self);
} }
pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool { pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {

View file

@ -17,17 +17,17 @@ const eql = @import("std").mem.eql;
const Self = @This(); const Self = @This();
const input_buffer_size = 1024; const input_buffer_size = 1024;
a: Allocator, allocator: Allocator,
input: ArrayList(u8), input: ArrayList(u8),
last_cmd: []const u8 = "", last_cmd: []const u8 = "",
leader: ?struct { keypress: u32, modifiers: u32 } = null, leader: ?struct { keypress: u32, modifiers: u32 } = null,
commands: Commands = undefined, commands: Commands = undefined,
pub fn create(a: Allocator) !tui.Mode { pub fn create(allocator: Allocator) !tui.Mode {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.input = try ArrayList(u8).initCapacity(a, input_buffer_size), .input = try ArrayList(u8).initCapacity(allocator, input_buffer_size),
}; };
try self.commands.init(self); try self.commands.init(self);
return .{ return .{
@ -42,7 +42,7 @@ pub fn create(a: Allocator) !tui.Mode {
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
self.commands.deinit(); self.commands.deinit();
self.input.deinit(); self.input.deinit();
self.a.destroy(self); self.allocator.destroy(self);
} }
pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool { pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {

View file

@ -17,18 +17,18 @@ const eql = @import("std").mem.eql;
const Self = @This(); const Self = @This();
const input_buffer_size = 1024; const input_buffer_size = 1024;
a: Allocator, allocator: Allocator,
input: ArrayList(u8), input: ArrayList(u8),
last_cmd: []const u8 = "", last_cmd: []const u8 = "",
leader: ?struct { keypress: u32, modifiers: u32 } = null, leader: ?struct { keypress: u32, modifiers: u32 } = null,
count: usize = 0, count: usize = 0,
commands: Commands = undefined, commands: Commands = undefined,
pub fn create(a: Allocator) !tui.Mode { pub fn create(allocator: Allocator) !tui.Mode {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.input = try ArrayList(u8).initCapacity(a, input_buffer_size), .input = try ArrayList(u8).initCapacity(allocator, input_buffer_size),
}; };
try self.commands.init(self); try self.commands.init(self);
return .{ return .{
@ -44,7 +44,7 @@ pub fn create(a: Allocator) !tui.Mode {
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
self.commands.deinit(); self.commands.deinit();
self.input.deinit(); self.input.deinit();
self.a.destroy(self); self.allocator.destroy(self);
} }
pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool { pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {

View file

@ -17,18 +17,18 @@ const eql = @import("std").mem.eql;
const Self = @This(); const Self = @This();
const input_buffer_size = 1024; const input_buffer_size = 1024;
a: Allocator, allocator: Allocator,
input: ArrayList(u8), input: ArrayList(u8),
last_cmd: []const u8 = "", last_cmd: []const u8 = "",
leader: ?struct { keypress: u32, modifiers: u32 } = null, leader: ?struct { keypress: u32, modifiers: u32 } = null,
count: usize = 0, count: usize = 0,
commands: Commands = undefined, commands: Commands = undefined,
pub fn create(a: Allocator) !tui.Mode { pub fn create(allocator: Allocator) !tui.Mode {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.input = try ArrayList(u8).initCapacity(a, input_buffer_size), .input = try ArrayList(u8).initCapacity(allocator, input_buffer_size),
}; };
try self.commands.init(self); try self.commands.init(self);
return .{ return .{
@ -44,7 +44,7 @@ pub fn create(a: Allocator) !tui.Mode {
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
self.commands.deinit(); self.commands.deinit();
self.input.deinit(); self.input.deinit();
self.a.destroy(self); self.allocator.destroy(self);
} }
pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool { pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {

View file

@ -12,14 +12,14 @@ const EventHandler = @import("../../EventHandler.zig");
const Self = @This(); const Self = @This();
a: std.mem.Allocator, allocator: std.mem.Allocator,
f: usize = 0, f: usize = 0,
leader: ?struct { keypress: u32, modifiers: u32 } = null, leader: ?struct { keypress: u32, modifiers: u32 } = null,
pub fn create(a: std.mem.Allocator) !tui.Mode { pub fn create(allocator: std.mem.Allocator) !tui.Mode {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
}; };
return .{ return .{
.handler = EventHandler.to_owned(self), .handler = EventHandler.to_owned(self),
@ -30,7 +30,7 @@ pub fn create(a: std.mem.Allocator) !tui.Mode {
} }
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
self.a.destroy(self); self.allocator.destroy(self);
} }
pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool { pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {

View file

@ -17,17 +17,17 @@ const eql = @import("std").mem.eql;
const Self = @This(); const Self = @This();
const input_buffer_size = 1024; const input_buffer_size = 1024;
a: Allocator, allocator: Allocator,
input: ArrayList(u8), input: ArrayList(u8),
last_cmd: []const u8 = "", last_cmd: []const u8 = "",
leader: ?struct { keypress: u32, modifiers: u32 } = null, leader: ?struct { keypress: u32, modifiers: u32 } = null,
commands: Commands = undefined, commands: Commands = undefined,
pub fn create(a: Allocator) !tui.Mode { pub fn create(allocator: Allocator) !tui.Mode {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.input = try ArrayList(u8).initCapacity(a, input_buffer_size), .input = try ArrayList(u8).initCapacity(allocator, input_buffer_size),
}; };
try self.commands.init(self); try self.commands.init(self);
return .{ return .{
@ -42,7 +42,7 @@ pub fn create(a: Allocator) !tui.Mode {
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
self.commands.deinit(); self.commands.deinit();
self.input.deinit(); self.input.deinit();
self.a.destroy(self); self.allocator.destroy(self);
} }
pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool { pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {

View file

@ -17,18 +17,18 @@ const eql = @import("std").mem.eql;
const Self = @This(); const Self = @This();
const input_buffer_size = 1024; const input_buffer_size = 1024;
a: Allocator, allocator: Allocator,
input: ArrayList(u8), input: ArrayList(u8),
last_cmd: []const u8 = "", last_cmd: []const u8 = "",
leader: ?struct { keypress: u32, modifiers: u32 } = null, leader: ?struct { keypress: u32, modifiers: u32 } = null,
count: usize = 0, count: usize = 0,
commands: Commands = undefined, commands: Commands = undefined,
pub fn create(a: Allocator) !tui.Mode { pub fn create(allocator: Allocator) !tui.Mode {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.input = try ArrayList(u8).initCapacity(a, input_buffer_size), .input = try ArrayList(u8).initCapacity(allocator, input_buffer_size),
}; };
try self.commands.init(self); try self.commands.init(self);
return .{ return .{
@ -44,7 +44,7 @@ pub fn create(a: Allocator) !tui.Mode {
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
self.commands.deinit(); self.commands.deinit();
self.input.deinit(); self.input.deinit();
self.a.destroy(self); self.allocator.destroy(self);
} }
pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool { pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {

View file

@ -17,18 +17,18 @@ const eql = @import("std").mem.eql;
const Self = @This(); const Self = @This();
const input_buffer_size = 1024; const input_buffer_size = 1024;
a: Allocator, allocator: Allocator,
input: ArrayList(u8), input: ArrayList(u8),
last_cmd: []const u8 = "", last_cmd: []const u8 = "",
leader: ?struct { keypress: u32, modifiers: u32 } = null, leader: ?struct { keypress: u32, modifiers: u32 } = null,
count: usize = 0, count: usize = 0,
commands: Commands = undefined, commands: Commands = undefined,
pub fn create(a: Allocator) !tui.Mode { pub fn create(allocator: Allocator) !tui.Mode {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.input = try ArrayList(u8).initCapacity(a, input_buffer_size), .input = try ArrayList(u8).initCapacity(allocator, input_buffer_size),
}; };
try self.commands.init(self); try self.commands.init(self);
return .{ return .{
@ -44,7 +44,7 @@ pub fn create(a: Allocator) !tui.Mode {
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
self.commands.deinit(); self.commands.deinit();
self.input.deinit(); self.input.deinit();
self.a.destroy(self); self.allocator.destroy(self);
} }
pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool { pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {

View file

@ -19,7 +19,7 @@ const max_complete_paths = 1024;
pub fn Create(options: type) type { pub fn Create(options: type) type {
return struct { return struct {
a: std.mem.Allocator, allocator: std.mem.Allocator,
file_path: std.ArrayList(u8), file_path: std.ArrayList(u8),
query: std.ArrayList(u8), query: std.ArrayList(u8),
match: std.ArrayList(u8), match: std.ArrayList(u8),
@ -34,14 +34,14 @@ pub fn Create(options: type) type {
type: enum { dir, file, link }, type: enum { dir, file, link },
}; };
pub fn create(a: std.mem.Allocator, _: command.Context) !*Self { pub fn create(allocator: std.mem.Allocator, _: command.Context) !*Self {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.file_path = std.ArrayList(u8).init(a), .file_path = std.ArrayList(u8).init(allocator),
.query = std.ArrayList(u8).init(a), .query = std.ArrayList(u8).init(allocator),
.match = std.ArrayList(u8).init(a), .match = std.ArrayList(u8).init(allocator),
.entries = std.ArrayList(Entry).init(a), .entries = std.ArrayList(Entry).init(allocator),
}; };
try tui.current().message_filters.add(MessageFilter.bind(self, receive_path_entry)); try tui.current().message_filters.add(MessageFilter.bind(self, receive_path_entry));
try options.load_entries(self); try options.load_entries(self);
@ -57,7 +57,7 @@ pub fn Create(options: type) type {
self.match.deinit(); self.match.deinit();
self.query.deinit(); self.query.deinit();
self.file_path.deinit(); self.file_path.deinit();
self.a.destroy(self); self.allocator.destroy(self);
} }
pub fn handler(self: *Self) EventHandler { pub fn handler(self: *Self) EventHandler {
@ -171,7 +171,7 @@ pub fn Create(options: type) type {
} }
fn clear_entries(self: *Self) void { fn clear_entries(self: *Self) void {
for (self.entries.items) |entry| self.a.free(entry.name); for (self.entries.items) |entry| self.allocator.free(entry.name);
self.entries.clearRetainingCapacity(); self.entries.clearRetainingCapacity();
} }
@ -246,11 +246,11 @@ pub fn Create(options: type) type {
var path: []const u8 = undefined; var path: []const u8 = undefined;
var file_name: []const u8 = undefined; var file_name: []const u8 = undefined;
if (try m.match(.{ tp.any, tp.any, tp.any, tp.extract(&path), "DIR", tp.extract(&file_name) })) { if (try m.match(.{ tp.any, tp.any, tp.any, tp.extract(&path), "DIR", tp.extract(&file_name) })) {
(try self.entries.addOne()).* = .{ .name = try self.a.dupe(u8, file_name), .type = .dir }; (try self.entries.addOne()).* = .{ .name = try self.allocator.dupe(u8, file_name), .type = .dir };
} else if (try m.match(.{ tp.any, tp.any, tp.any, tp.extract(&path), "LINK", tp.extract(&file_name) })) { } else if (try m.match(.{ tp.any, tp.any, tp.any, tp.extract(&path), "LINK", tp.extract(&file_name) })) {
(try self.entries.addOne()).* = .{ .name = try self.a.dupe(u8, file_name), .type = .link }; (try self.entries.addOne()).* = .{ .name = try self.allocator.dupe(u8, file_name), .type = .link };
} else if (try m.match(.{ tp.any, tp.any, tp.any, tp.extract(&path), "FILE", tp.extract(&file_name) })) { } else if (try m.match(.{ tp.any, tp.any, tp.any, tp.extract(&path), "FILE", tp.extract(&file_name) })) {
(try self.entries.addOne()).* = .{ .name = try self.a.dupe(u8, file_name), .type = .file }; (try self.entries.addOne()).* = .{ .name = try self.allocator.dupe(u8, file_name), .type = .file };
} else { } else {
log.logger("file_browser").err("receive", tp.unexpected(m)); log.logger("file_browser").err("receive", tp.unexpected(m));
} }

View file

@ -18,7 +18,7 @@ const ArrayList = @import("std").ArrayList;
const Self = @This(); const Self = @This();
a: Allocator, allocator: Allocator,
input: ArrayList(u8), input: ArrayList(u8),
last_input: ArrayList(u8), last_input: ArrayList(u8),
start_view: ed.View, start_view: ed.View,
@ -26,20 +26,20 @@ start_cursor: ed.Cursor,
editor: *ed.Editor, editor: *ed.Editor,
history_pos: ?usize = null, history_pos: ?usize = null,
pub fn create(a: Allocator, _: command.Context) !*Self { pub fn create(allocator: Allocator, _: command.Context) !*Self {
if (tui.current().mainview.dynamic_cast(mainview)) |mv_| if (mv_.get_editor()) |editor| { if (tui.current().mainview.dynamic_cast(mainview)) |mv_| if (mv_.get_editor()) |editor| {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.input = ArrayList(u8).init(a), .input = ArrayList(u8).init(allocator),
.last_input = ArrayList(u8).init(a), .last_input = ArrayList(u8).init(allocator),
.start_view = editor.view, .start_view = editor.view,
.start_cursor = editor.get_primary().cursor, .start_cursor = editor.get_primary().cursor,
.editor = editor, .editor = editor,
}; };
if (editor.get_primary().selection) |sel| ret: { if (editor.get_primary().selection) |sel| ret: {
const text = editor.get_selection(sel, self.a) catch break :ret; const text = editor.get_selection(sel, self.allocator) catch break :ret;
defer self.a.free(text); defer self.allocator.free(text);
try self.input.appendSlice(text); try self.input.appendSlice(text);
} }
return self; return self;
@ -50,7 +50,7 @@ pub fn create(a: Allocator, _: command.Context) !*Self {
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
self.input.deinit(); self.input.deinit();
self.last_input.deinit(); self.last_input.deinit();
self.a.destroy(self); self.allocator.destroy(self);
} }
pub fn handler(self: *Self) EventHandler { pub fn handler(self: *Self) EventHandler {
@ -210,7 +210,7 @@ fn find_history_prev(self: *Self) void {
} else { } else {
self.history_pos = history.items.len - 1; self.history_pos = history.items.len - 1;
if (self.input.items.len > 0) if (self.input.items.len > 0)
self.editor.push_find_history(self.editor.a.dupe(u8, self.input.items) catch return); self.editor.push_find_history(self.editor.allocator.dupe(u8, self.input.items) catch return);
if (eql(u8, history.items[self.history_pos.?], self.input.items) and self.history_pos.? > 0) if (eql(u8, history.items[self.history_pos.?], self.input.items) and self.history_pos.? > 0)
self.history_pos = self.history_pos.? - 1; self.history_pos = self.history_pos.? - 1;
} }

View file

@ -17,23 +17,23 @@ const eql = @import("std").mem.eql;
const Self = @This(); const Self = @This();
a: Allocator, allocator: Allocator,
buf: [1024]u8 = undefined, buf: [1024]u8 = undefined,
input: []u8 = "", input: []u8 = "",
last_buf: [1024]u8 = undefined, last_buf: [1024]u8 = undefined,
last_input: []u8 = "", last_input: []u8 = "",
mainview: *mainview, mainview: *mainview,
pub fn create(a: Allocator, _: command.Context) !*Self { pub fn create(allocator: Allocator, _: command.Context) !*Self {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
if (tui.current().mainview.dynamic_cast(mainview)) |mv| { if (tui.current().mainview.dynamic_cast(mainview)) |mv| {
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.mainview = mv, .mainview = mv,
}; };
if (mv.get_editor()) |editor| if (editor.get_primary().selection) |sel| ret: { if (mv.get_editor()) |editor| if (editor.get_primary().selection) |sel| ret: {
const text = editor.get_selection(sel, self.a) catch break :ret; const text = editor.get_selection(sel, self.allocator) catch break :ret;
defer self.a.free(text); defer self.allocator.free(text);
@memcpy(self.buf[0..text.len], text); @memcpy(self.buf[0..text.len], text);
self.input = self.buf[0..text.len]; self.input = self.buf[0..text.len];
}; };
@ -43,7 +43,7 @@ pub fn create(a: Allocator, _: command.Context) !*Self {
} }
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
self.a.destroy(self); self.allocator.destroy(self);
} }
pub fn handler(self: *Self) EventHandler { pub fn handler(self: *Self) EventHandler {

View file

@ -16,16 +16,16 @@ const fmt = @import("std").fmt;
const Self = @This(); const Self = @This();
a: Allocator, allocator: Allocator,
buf: [30]u8 = undefined, buf: [30]u8 = undefined,
input: ?usize = null, input: ?usize = null,
start: usize, start: usize,
pub fn create(a: Allocator, _: command.Context) !*Self { pub fn create(allocator: Allocator, _: command.Context) !*Self {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
if (tui.current().mainview.dynamic_cast(mainview)) |mv_| if (mv_.get_editor()) |editor| { if (tui.current().mainview.dynamic_cast(mainview)) |mv_| if (mv_.get_editor()) |editor| {
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.start = editor.get_primary().cursor.row + 1, .start = editor.get_primary().cursor.row + 1,
}; };
return self; return self;
@ -34,7 +34,7 @@ pub fn create(a: Allocator, _: command.Context) !*Self {
} }
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
self.a.destroy(self); self.allocator.destroy(self);
} }
pub fn handler(self: *Self) EventHandler { pub fn handler(self: *Self) EventHandler {

View file

@ -17,7 +17,7 @@ const fmt = @import("std").fmt;
const Self = @This(); const Self = @This();
a: Allocator, allocator: Allocator,
key: [6]u8 = undefined, key: [6]u8 = undefined,
direction: Direction, direction: Direction,
operation: Operation, operation: Operation,
@ -32,13 +32,13 @@ const Operation = enum {
select, select,
}; };
pub fn create(a: Allocator, ctx: command.Context) !*Self { pub fn create(allocator: Allocator, ctx: command.Context) !*Self {
var right: bool = true; var right: bool = true;
const select = if (tui.current().mainview.dynamic_cast(mainview)) |mv| if (mv.get_editor()) |editor| if (editor.get_primary().selection) |_| true else false else false else false; const select = if (tui.current().mainview.dynamic_cast(mainview)) |mv| if (mv.get_editor()) |editor| if (editor.get_primary().selection) |_| true else false else false else false;
_ = ctx.args.match(.{tp.extract(&right)}) catch return error.NotFound; _ = ctx.args.match(.{tp.extract(&right)}) catch return error.NotFound;
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.direction = if (right) .right else .left, .direction = if (right) .right else .left,
.operation = if (select) .select else .move, .operation = if (select) .select else .move,
}; };
@ -46,7 +46,7 @@ pub fn create(a: Allocator, ctx: command.Context) !*Self {
} }
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
self.a.destroy(self); self.allocator.destroy(self);
} }
pub fn handler(self: *Self) EventHandler { pub fn handler(self: *Self) EventHandler {

View file

@ -26,8 +26,8 @@ pub fn load_entries(self: *Type) !void {
if (std.mem.lastIndexOf(u8, old_path, "/")) |pos| if (std.mem.lastIndexOf(u8, old_path, "/")) |pos|
try self.file_path.appendSlice(old_path[0 .. pos + 1]); try self.file_path.appendSlice(old_path[0 .. pos + 1]);
if (editor.get_primary().selection) |sel| ret: { if (editor.get_primary().selection) |sel| ret: {
const text = editor.get_selection(sel, self.a) catch break :ret; const text = editor.get_selection(sel, self.allocator) catch break :ret;
defer self.a.free(text); defer self.allocator.free(text);
if (!(text.len > 2 and std.mem.eql(u8, text[0..2], ".."))) if (!(text.len > 2 and std.mem.eql(u8, text[0..2], "..")))
self.file_path.clearRetainingCapacity(); self.file_path.clearRetainingCapacity();
try self.file_path.appendSlice(text); try self.file_path.appendSlice(text);

View file

@ -23,8 +23,8 @@ pub fn load_entries(self: *Type) !void {
if (tui.current().mainview.dynamic_cast(mainview)) |mv_| if (mv_.get_editor()) |editor| { if (tui.current().mainview.dynamic_cast(mainview)) |mv_| if (mv_.get_editor()) |editor| {
try self.file_path.appendSlice(editor.file_path orelse ""); try self.file_path.appendSlice(editor.file_path orelse "");
if (editor.get_primary().selection) |sel| ret: { if (editor.get_primary().selection) |sel| ret: {
const text = editor.get_selection(sel, self.a) catch break :ret; const text = editor.get_selection(sel, self.allocator) catch break :ret;
defer self.a.free(text); defer self.allocator.free(text);
if (!(text.len > 2 and std.mem.eql(u8, text[0..2], ".."))) if (!(text.len > 2 and std.mem.eql(u8, text[0..2], "..")))
self.file_path.clearRetainingCapacity(); self.file_path.clearRetainingCapacity();
try self.file_path.appendSlice(text); try self.file_path.appendSlice(text);

View file

@ -24,7 +24,7 @@ pub fn load_entries(palette: *Type) !void {
} }
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void { pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
var value = std.ArrayList(u8).init(palette.a); var value = std.ArrayList(u8).init(palette.allocator);
defer value.deinit(); defer value.deinit();
const writer = value.writer(); const writer = value.writer();
try cbor.writeValue(writer, entry.name); try cbor.writeValue(writer, entry.name);

View file

@ -25,7 +25,7 @@ const mainview = @import("../../mainview.zig");
const Self = @This(); const Self = @This();
const max_recent_files: usize = 25; const max_recent_files: usize = 25;
a: std.mem.Allocator, allocator: std.mem.Allocator,
f: usize = 0, f: usize = 0,
menu: *Menu.State(*Self), menu: *Menu.State(*Self),
inputbox: *InputBox.State(*Self), inputbox: *InputBox.State(*Self),
@ -36,18 +36,18 @@ need_select_first: bool = true,
longest: usize = 0, longest: usize = 0,
commands: Commands = undefined, commands: Commands = undefined,
pub fn create(a: std.mem.Allocator) !tui.Mode { pub fn create(allocator: std.mem.Allocator) !tui.Mode {
const mv = tui.current().mainview.dynamic_cast(mainview) orelse return error.NotFound; const mv = tui.current().mainview.dynamic_cast(mainview) orelse return error.NotFound;
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.menu = try Menu.create(*Self, a, tui.current().mainview, .{ .menu = try Menu.create(*Self, allocator, tui.current().mainview, .{
.ctx = self, .ctx = self,
.on_render = on_render_menu, .on_render = on_render_menu,
.on_resize = on_resize_menu, .on_resize = on_resize_menu,
}), }),
.logger = log.logger(@typeName(Self)), .logger = log.logger(@typeName(Self)),
.inputbox = (try self.menu.add_header(try InputBox.create(*Self, self.a, self.menu.menu.parent, .{ .inputbox = (try self.menu.add_header(try InputBox.create(*Self, self.allocator, self.menu.menu.parent, .{
.ctx = self, .ctx = self,
.label = "Search files by name", .label = "Search files by name",
}))).dynamic_cast(InputBox.State(*Self)) orelse unreachable, }))).dynamic_cast(InputBox.State(*Self)) orelse unreachable,
@ -71,7 +71,7 @@ pub fn deinit(self: *Self) void {
if (tui.current().mainview.dynamic_cast(mainview)) |mv| if (tui.current().mainview.dynamic_cast(mainview)) |mv|
mv.floating_views.remove(self.menu.container_widget); mv.floating_views.remove(self.menu.container_widget);
self.logger.deinit(); self.logger.deinit();
self.a.destroy(self); self.allocator.destroy(self);
} }
inline fn menu_width(self: *Self) usize { inline fn menu_width(self: *Self) usize {
@ -141,7 +141,7 @@ fn menu_action_open_file(menu: **Menu.State(*Self), button: *Button.State(*Menu.
} }
fn add_item(self: *Self, file_name: []const u8, matches: ?[]const u8) !void { fn add_item(self: *Self, file_name: []const u8, matches: ?[]const u8) !void {
var label = std.ArrayList(u8).init(self.a); var label = std.ArrayList(u8).init(self.allocator);
defer label.deinit(); defer label.deinit();
const writer = label.writer(); const writer = label.writer();
try cbor.writeValue(writer, file_name); try cbor.writeValue(writer, file_name);

View file

@ -24,24 +24,24 @@ pub const Match = struct {
pub fn deinit(palette: *Type) void { pub fn deinit(palette: *Type) void {
for (palette.entries.items) |entry| for (palette.entries.items) |entry|
palette.a.free(entry.name); palette.allocator.free(entry.name);
} }
pub fn load_entries(palette: *Type) !void { pub fn load_entries(palette: *Type) !void {
const rsp = try project_manager.request_recent_projects(palette.a); const rsp = try project_manager.request_recent_projects(palette.allocator);
defer palette.a.free(rsp.buf); defer palette.allocator.free(rsp.buf);
var iter: []const u8 = rsp.buf; var iter: []const u8 = rsp.buf;
var len = try cbor.decodeArrayHeader(&iter); var len = try cbor.decodeArrayHeader(&iter);
while (len > 0) : (len -= 1) { while (len > 0) : (len -= 1) {
var name_: []const u8 = undefined; var name_: []const u8 = undefined;
if (try cbor.matchValue(&iter, cbor.extract(&name_))) { if (try cbor.matchValue(&iter, cbor.extract(&name_))) {
(try palette.entries.addOne()).* = .{ .name = try palette.a.dupe(u8, name_) }; (try palette.entries.addOne()).* = .{ .name = try palette.allocator.dupe(u8, name_) };
} else return error.InvalidMessageField; } else return error.InvalidMessageField;
} }
} }
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void { pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
var value = std.ArrayList(u8).init(palette.a); var value = std.ArrayList(u8).init(palette.allocator);
defer value.deinit(); defer value.deinit();
const writer = value.writer(); const writer = value.writer();
try cbor.writeValue(writer, entry.name); try cbor.writeValue(writer, entry.name);

View file

@ -26,7 +26,7 @@ const max_menu_width = 80;
pub fn Create(options: type) type { pub fn Create(options: type) type {
return struct { return struct {
a: std.mem.Allocator, allocator: std.mem.Allocator,
menu: *Menu.State(*Self), menu: *Menu.State(*Self),
inputbox: *InputBox.State(*Self), inputbox: *InputBox.State(*Self),
logger: log.Logger, logger: log.Logger,
@ -47,12 +47,12 @@ pub fn Create(options: type) type {
pub const MenuState = Menu.State(*Self); pub const MenuState = Menu.State(*Self);
pub const ButtonState = Button.State(*Menu.State(*Self)); pub const ButtonState = Button.State(*Menu.State(*Self));
pub fn create(a: std.mem.Allocator) !tui.Mode { pub fn create(allocator: std.mem.Allocator) !tui.Mode {
const mv = tui.current().mainview.dynamic_cast(mainview) orelse return error.NotFound; const mv = tui.current().mainview.dynamic_cast(mainview) orelse return error.NotFound;
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.menu = try Menu.create(*Self, a, tui.current().mainview, .{ .menu = try Menu.create(*Self, allocator, tui.current().mainview, .{
.ctx = self, .ctx = self,
.on_render = on_render_menu, .on_render = on_render_menu,
.on_resize = on_resize_menu, .on_resize = on_resize_menu,
@ -61,13 +61,13 @@ pub fn Create(options: type) type {
.on_click5 = mouse_click_button5, .on_click5 = mouse_click_button5,
}), }),
.logger = log.logger(@typeName(Self)), .logger = log.logger(@typeName(Self)),
.inputbox = (try self.menu.add_header(try InputBox.create(*Self, self.a, self.menu.menu.parent, .{ .inputbox = (try self.menu.add_header(try InputBox.create(*Self, self.allocator, self.menu.menu.parent, .{
.ctx = self, .ctx = self,
.label = options.label, .label = options.label,
}))).dynamic_cast(InputBox.State(*Self)) orelse unreachable, }))).dynamic_cast(InputBox.State(*Self)) orelse unreachable,
.hints = if (tui.current().input_mode) |m| m.keybind_hints else null, .hints = if (tui.current().input_mode) |m| m.keybind_hints else null,
.view_rows = get_view_rows(tui.current().screen()), .view_rows = get_view_rows(tui.current().screen()),
.entries = std.ArrayList(Entry).init(a), .entries = std.ArrayList(Entry).init(allocator),
}; };
self.menu.scrollbar.?.style_factory = scrollbar_style; self.menu.scrollbar.?.style_factory = scrollbar_style;
if (self.hints) |hints| { if (self.hints) |hints| {
@ -96,7 +96,7 @@ pub fn Create(options: type) type {
if (tui.current().mainview.dynamic_cast(mainview)) |mv| if (tui.current().mainview.dynamic_cast(mainview)) |mv|
mv.floating_views.remove(self.menu.container_widget); mv.floating_views.remove(self.menu.container_widget);
self.logger.deinit(); self.logger.deinit();
self.a.destroy(self); self.allocator.destroy(self);
} }
fn scrollbar_style(sb: *scrollbar_v, theme: *const Widget.Theme) Widget.Theme.Style { fn scrollbar_style(sb: *scrollbar_v, theme: *const Widget.Theme) Widget.Theme.Style {
@ -325,7 +325,7 @@ pub fn Create(options: type) type {
fn query_entries(self: *Self, query: []const u8) error{OutOfMemory}!usize { fn query_entries(self: *Self, query: []const u8) error{OutOfMemory}!usize {
var searcher = try fuzzig.Ascii.init( var searcher = try fuzzig.Ascii.init(
self.a, self.allocator,
self.longest, // haystack max size self.longest, // haystack max size
self.longest, // needle max size self.longest, // needle max size
.{ .case_sensitive = false }, .{ .case_sensitive = false },
@ -338,7 +338,7 @@ pub fn Create(options: type) type {
matches: []const usize, matches: []const usize,
}; };
var matches = std.ArrayList(Match).init(self.a); var matches = std.ArrayList(Match).init(self.allocator);
for (self.entries.items) |*entry| { for (self.entries.items) |*entry| {
const match = searcher.scoreMatches(entry.name, query); const match = searcher.scoreMatches(entry.name, query);
@ -346,7 +346,7 @@ pub fn Create(options: type) type {
(try matches.addOne()).* = .{ (try matches.addOne()).* = .{
.entry = entry, .entry = entry,
.score = score, .score = score,
.matches = try self.a.dupe(usize, match.matches), .matches = try self.allocator.dupe(usize, match.matches),
}; };
} }
if (matches.items.len == 0) return 0; if (matches.items.len == 0) return 0;

View file

@ -29,7 +29,7 @@ pub fn load_entries(palette: *Type) !void {
} }
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void { pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
var value = std.ArrayList(u8).init(palette.a); var value = std.ArrayList(u8).init(palette.allocator);
defer value.deinit(); defer value.deinit();
const writer = value.writer(); const writer = value.writer();
try cbor.writeValue(writer, entry.name); try cbor.writeValue(writer, entry.name);

View file

@ -28,8 +28,8 @@ style_factory: ?*const fn (self: *Self, theme: *const Widget.Theme) Widget.Theme
const Self = @This(); const Self = @This();
pub fn create(a: Allocator, parent: Widget, event_source: ?Widget, event_sink: EventHandler) !Widget { pub fn create(allocator: Allocator, parent: Widget, event_source: ?Widget, event_sink: EventHandler) !Widget {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent.plane.*), .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent.plane.*),
.event_sink = event_sink, .event_sink = event_sink,
@ -44,9 +44,9 @@ pub fn widget(self: *Self) Widget {
return Widget.to(self); return Widget.to(self);
} }
pub fn deinit(self: *Self, a: Allocator) void { pub fn deinit(self: *Self, allocator: Allocator) void {
self.plane.deinit(); self.plane.deinit();
a.destroy(self); allocator.destroy(self);
} }
pub fn layout(_: *Self) Widget.Layout { pub fn layout(_: *Self) Widget.Layout {

View file

@ -9,13 +9,13 @@ const Self = @This();
pub const Style = enum { none, grip }; pub const Style = enum { none, grip };
pub fn create(a: std.mem.Allocator, parent: Widget, config: []const u8, style: Style, event_handler: ?Widget.EventHandler) !Widget { pub fn create(allocator: std.mem.Allocator, parent: Widget, config: []const u8, style: Style, event_handler: ?Widget.EventHandler) !Widget {
var w = try WidgetList.createH(a, parent, "statusbar", .{ .static = 1 }); var w = try WidgetList.createH(allocator, parent, "statusbar", .{ .static = 1 });
if (style == .grip) w.after_render = render_grip; if (style == .grip) w.after_render = render_grip;
w.ctx = w; w.ctx = w;
var it = std.mem.splitScalar(u8, config, ' '); var it = std.mem.splitScalar(u8, config, ' ');
while (it.next()) |widget_name| while (it.next()) |widget_name|
try w.add(try status_widget.create(widget_name, a, w.plane, event_handler) orelse continue); try w.add(try status_widget.create(widget_name, allocator, w.plane, event_handler) orelse continue);
return w.widget(); return w.widget();
} }

View file

@ -12,8 +12,8 @@ const Self = @This();
pub fn Create(comptime layout_: Widget.Layout) @import("widget.zig").CreateFunction { pub fn Create(comptime layout_: Widget.Layout) @import("widget.zig").CreateFunction {
return struct { return struct {
fn create(a: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent), .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
.layout = layout_, .layout = layout_,
@ -24,9 +24,9 @@ pub fn Create(comptime layout_: Widget.Layout) @import("widget.zig").CreateFunct
}.create; }.create;
} }
pub fn deinit(self: *Self, a: std.mem.Allocator) void { pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
self.plane.deinit(); self.plane.deinit();
a.destroy(self); allocator.destroy(self);
} }
pub fn layout(self: *Self) Widget.Layout { pub fn layout(self: *Self) Widget.Layout {

View file

@ -26,22 +26,22 @@ const Level = enum {
err, err,
}; };
pub fn create(a: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { pub fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
var env = std.process.getEnvMap(a) catch |e| return tp.exit_error(e, @errorReturnTrace()); var env = std.process.getEnvMap(allocator) catch |e| return tp.exit_error(e, @errorReturnTrace());
defer env.deinit(); defer env.deinit();
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.allocator = a, .allocator = allocator,
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent), .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
.on_event = event_handler, .on_event = event_handler,
.tz = zeit.local(a, &env) catch |e| return tp.exit_error(e, @errorReturnTrace()), .tz = zeit.local(allocator, &env) catch |e| return tp.exit_error(e, @errorReturnTrace()),
}; };
try tui.current().message_filters.add(MessageFilter.bind(self, receive_tick)); try tui.current().message_filters.add(MessageFilter.bind(self, receive_tick));
self.update_tick_timer(.init); self.update_tick_timer(.init);
return Widget.to(self); return Widget.to(self);
} }
pub fn deinit(self: *Self, a: std.mem.Allocator) void { pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
tui.current().message_filters.remove_ptr(self); tui.current().message_filters.remove_ptr(self);
if (self.tick_timer) |*t| { if (self.tick_timer) |*t| {
t.cancel() catch {}; t.cancel() catch {};
@ -50,7 +50,7 @@ pub fn deinit(self: *Self, a: std.mem.Allocator) void {
} }
self.tz.deinit(); self.tz.deinit();
self.plane.deinit(); self.plane.deinit();
a.destroy(self); allocator.destroy(self);
} }
pub fn receive(self: *Self, from: tp.pid_ref, m: tp.message) error{Exit}!bool { pub fn receive(self: *Self, from: tp.pid_ref, m: tp.message) error{Exit}!bool {

View file

@ -19,8 +19,8 @@ rendered: [:0]const u8 = "",
const Self = @This(); const Self = @This();
pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { pub fn create(allocator: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
return Button.create_widget(Self, a, parent, .{ return Button.create_widget(Self, allocator, parent, .{
.ctx = .{}, .ctx = .{},
.label = "", .label = "",
.on_click = on_click, .on_click = on_click,

View file

@ -13,7 +13,7 @@ const Button = @import("../Button.zig");
const command = @import("../command.zig"); const command = @import("../command.zig");
const tui = @import("../tui.zig"); const tui = @import("../tui.zig");
a: Allocator, allocator: Allocator,
name: []const u8, name: []const u8,
name_buf: [512]u8 = undefined, name_buf: [512]u8 = undefined,
previous_title: []const u8 = "", previous_title: []const u8 = "",
@ -34,10 +34,10 @@ file: bool = false,
const project_icon = ""; const project_icon = "";
const Self = @This(); const Self = @This();
pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { pub fn create(allocator: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
const btn = try Button.create(Self, a, parent, .{ const btn = try Button.create(Self, allocator, parent, .{
.ctx = .{ .ctx = .{
.a = a, .allocator = allocator,
.name = "", .name = "",
.file_type = "", .file_type = "",
.lines = 0, .lines = 0,

View file

@ -31,10 +31,10 @@ const Self = @This();
const idle_msg = "🐶"; const idle_msg = "🐶";
pub const width = idle_msg.len + 20; pub const width = idle_msg.len + 20;
pub fn create(a: Allocator, parent: Plane, _: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { pub fn create(allocator: Allocator, parent: Plane, _: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
var frame_rate = tp.env.get().num("frame-rate"); var frame_rate = tp.env.get().num("frame-rate");
if (frame_rate == 0) frame_rate = 60; if (frame_rate == 0) frame_rate = 60;
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent), .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
.wipe_after_frames = @divTrunc(frame_rate, 2), .wipe_after_frames = @divTrunc(frame_rate, 2),
@ -47,10 +47,10 @@ pub fn widget(self: *Self) Widget {
return Widget.to(self); return Widget.to(self);
} }
pub fn deinit(self: *Self, a: Allocator) void { pub fn deinit(self: *Self, allocator: Allocator) void {
tui.current().input_listeners.remove_ptr(self); tui.current().input_listeners.remove_ptr(self);
self.plane.deinit(); self.plane.deinit();
a.destroy(self); allocator.destroy(self);
} }
pub fn layout(_: *Self) Widget.Layout { pub fn layout(_: *Self) Widget.Layout {

View file

@ -18,8 +18,8 @@ rendered: [:0]const u8 = "",
const Self = @This(); const Self = @This();
pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { pub fn create(allocator: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
return Button.create_widget(Self, a, parent, .{ return Button.create_widget(Self, allocator, parent, .{
.ctx = .{}, .ctx = .{},
.label = "", .label = "",
.on_click = on_click, .on_click = on_click,

View file

@ -26,20 +26,20 @@ const Level = enum {
err, err,
}; };
pub fn create(a: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { pub fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent), .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
.msg = std.ArrayList(u8).init(a), .msg = std.ArrayList(u8).init(allocator),
.on_event = event_handler, .on_event = event_handler,
}; };
logview.init(a); logview.init(allocator);
try tui.current().message_filters.add(MessageFilter.bind(self, receive_log)); try tui.current().message_filters.add(MessageFilter.bind(self, receive_log));
try log.subscribe(); try log.subscribe();
return Widget.to(self); return Widget.to(self);
} }
pub fn deinit(self: *Self, a: std.mem.Allocator) void { pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
if (self.clear_timer) |*t| { if (self.clear_timer) |*t| {
t.cancel() catch {}; t.cancel() catch {};
t.deinit(); t.deinit();
@ -49,7 +49,7 @@ pub fn deinit(self: *Self, a: std.mem.Allocator) void {
log.unsubscribe() catch {}; log.unsubscribe() catch {};
tui.current().message_filters.remove_ptr(self); tui.current().message_filters.remove_ptr(self);
self.plane.deinit(); self.plane.deinit();
a.destroy(self); allocator.destroy(self);
} }
pub fn receive(self: *Self, from: tp.pid_ref, m: tp.message) error{Exit}!bool { pub fn receive(self: *Self, from: tp.pid_ref, m: tp.message) error{Exit}!bool {

View file

@ -15,8 +15,8 @@ const ed = @import("../editor.zig");
const tui = @import("../tui.zig"); const tui = @import("../tui.zig");
const CreateError = @import("widget.zig").CreateError; const CreateError = @import("widget.zig").CreateError;
pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!Widget { pub fn create(allocator: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!Widget {
return Button.create_widget(void, a, parent, .{ return Button.create_widget(void, allocator, parent, .{
.ctx = {}, .ctx = {},
.label = tui.get_mode(), .label = tui.get_mode(),
.on_click = on_click, .on_click = on_click,

View file

@ -23,8 +23,8 @@ const Self = @This();
pub const width = 5; pub const width = 5;
pub fn create(a: Allocator, parent: Plane, _: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { pub fn create(allocator: Allocator, parent: Plane, _: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent), .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
}; };
@ -36,10 +36,10 @@ pub fn widget(self: *Self) Widget {
return Widget.to(self); return Widget.to(self);
} }
pub fn deinit(self: *Self, a: Allocator) void { pub fn deinit(self: *Self, allocator: Allocator) void {
tui.current().input_listeners.remove_ptr(self); tui.current().input_listeners.remove_ptr(self);
self.plane.deinit(); self.plane.deinit();
a.destroy(self); allocator.destroy(self);
} }
pub fn layout(_: *Self) Widget.Layout { pub fn layout(_: *Self) Widget.Layout {

View file

@ -19,8 +19,8 @@ on_event: ?Widget.EventHandler,
const Self = @This(); const Self = @This();
pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { pub fn create(allocator: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
const self: *Self = try a.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent), .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
.on_event = event_handler, .on_event = event_handler,
@ -28,9 +28,9 @@ pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler)
return Widget.to(self); return Widget.to(self);
} }
pub fn deinit(self: *Self, a: Allocator) void { pub fn deinit(self: *Self, allocator: Allocator) void {
self.plane.deinit(); self.plane.deinit();
a.destroy(self); allocator.destroy(self);
} }
pub fn layout(self: *Self) Widget.Layout { pub fn layout(self: *Self) Widget.Layout {

View file

@ -16,9 +16,9 @@ const widgets = std.static_string_map.StaticStringMap(CreateFunction).initCompti
.{ "clock", @import("clock.zig").create }, .{ "clock", @import("clock.zig").create },
}); });
pub const CreateError = error{ OutOfMemory, Exit }; pub const CreateError = error{ OutOfMemory, Exit };
pub const CreateFunction = *const fn (a: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!Widget; pub const CreateFunction = *const fn (allocator: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!Widget;
pub fn create(name: []const u8, a: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!?Widget { pub fn create(name: []const u8, allocator: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!?Widget {
const create_ = widgets.get(name) orelse return null; const create_ = widgets.get(name) orelse return null;
return try create_(a, parent, event_handler); return try create_(allocator, parent, event_handler);
} }

View file

@ -25,7 +25,7 @@ const Timer = std.time.Timer;
const Mutex = std.Thread.Mutex; const Mutex = std.Thread.Mutex;
const maxInt = std.math.maxInt; const maxInt = std.math.maxInt;
a: Allocator, allocator: Allocator,
rdr: renderer, rdr: renderer,
config: config, config: config,
frame_time: usize, // in microseconds frame_time: usize, // in microseconds
@ -68,30 +68,30 @@ const Self = @This();
const Receiver = tp.Receiver(*Self); const Receiver = tp.Receiver(*Self);
const Commands = command.Collection(cmds); const Commands = command.Collection(cmds);
const StartArgs = struct { a: Allocator }; const StartArgs = struct { allocator: Allocator };
pub fn spawn(a: Allocator, ctx: *tp.context, eh: anytype, env: ?*const tp.env) !tp.pid { pub fn spawn(allocator: Allocator, ctx: *tp.context, eh: anytype, env: ?*const tp.env) !tp.pid {
return try ctx.spawn_link(StartArgs{ .a = a }, start, "tui", eh, env); return try ctx.spawn_link(StartArgs{ .allocator = allocator }, start, "tui", eh, env);
} }
fn start(args: StartArgs) tp.result { fn start(args: StartArgs) tp.result {
_ = tp.set_trap(true); _ = tp.set_trap(true);
var self = init(args.a) catch |e| return tp.exit_error(e, @errorReturnTrace()); var self = init(args.allocator) catch |e| return tp.exit_error(e, @errorReturnTrace());
errdefer self.deinit(); errdefer self.deinit();
tp.receive(&self.receiver); tp.receive(&self.receiver);
} }
fn init(a: Allocator) !*Self { fn init(allocator: Allocator) !*Self {
var self = try a.create(Self); var self = try allocator.create(Self);
var conf_buf: ?[]const u8 = null; var conf_buf: ?[]const u8 = null;
var conf = root.read_config(a, &conf_buf); var conf = root.read_config(allocator, &conf_buf);
defer if (conf_buf) |buf| a.free(buf); defer if (conf_buf) |buf| allocator.free(buf);
const theme = get_theme_by_name(conf.theme) orelse get_theme_by_name("dark_modern") orelse return tp.exit("unknown theme"); const theme = get_theme_by_name(conf.theme) orelse get_theme_by_name("dark_modern") orelse return tp.exit("unknown theme");
conf.theme = theme.name; conf.theme = theme.name;
conf.input_mode = try a.dupe(u8, conf.input_mode); conf.input_mode = try allocator.dupe(u8, conf.input_mode);
conf.top_bar = try a.dupe(u8, conf.top_bar); conf.top_bar = try allocator.dupe(u8, conf.top_bar);
conf.bottom_bar = try a.dupe(u8, conf.bottom_bar); conf.bottom_bar = try allocator.dupe(u8, conf.bottom_bar);
const frame_rate: usize = @intCast(tp.env.get().num("frame-rate")); const frame_rate: usize = @intCast(tp.env.get().num("frame-rate"));
if (frame_rate != 0) if (frame_rate != 0)
@ -100,17 +100,17 @@ fn init(a: Allocator) !*Self {
const frame_clock = try tp.metronome.init(frame_time); const frame_clock = try tp.metronome.init(frame_time);
self.* = .{ self.* = .{
.a = a, .allocator = allocator,
.config = conf, .config = conf,
.rdr = try renderer.init(a, self, tp.env.get().is("no-alternate")), .rdr = try renderer.init(allocator, self, tp.env.get().is("no-alternate")),
.frame_time = frame_time, .frame_time = frame_time,
.frame_clock = frame_clock, .frame_clock = frame_clock,
.frame_clock_running = true, .frame_clock_running = true,
.receiver = Receiver.init(receive, self), .receiver = Receiver.init(receive, self),
.mainview = undefined, .mainview = undefined,
.message_filters = MessageFilter.List.init(a), .message_filters = MessageFilter.List.init(allocator),
.input_mode = null, .input_mode = null,
.input_listeners = EventHandler.List.init(a), .input_listeners = EventHandler.List.init(allocator),
.logger = log.logger("tui"), .logger = log.logger("tui"),
.init_timer = try tp.timeout.init_ms(init_delay, tp.message.fmt(.{"init"})), .init_timer = try tp.timeout.init_ms(init_delay, tp.message.fmt(.{"init"})),
.theme = theme, .theme = theme,
@ -131,13 +131,13 @@ fn init(a: Allocator) !*Self {
errdefer self.deinit(); errdefer self.deinit();
switch (builtin.os.tag) { switch (builtin.os.tag) {
.windows => { .windows => {
self.keepalive_timer = try tp.self_pid().delay_send_cancellable(a, "tui.keepalive", keepalive, .{"keepalive"}); self.keepalive_timer = try tp.self_pid().delay_send_cancellable(allocator, "tui.keepalive", keepalive, .{"keepalive"});
}, },
else => { else => {
try self.listen_sigwinch(); try self.listen_sigwinch();
}, },
} }
self.mainview = try mainview.create(a); self.mainview = try mainview.create(allocator);
self.resize(); self.resize();
self.set_terminal_style(); self.set_terminal_style();
try self.rdr.render(); try self.rdr.render();
@ -167,7 +167,7 @@ fn deinit(self: *Self) void {
} }
if (self.input_mode) |*m| m.deinit(); if (self.input_mode) |*m| m.deinit();
self.commands.deinit(); self.commands.deinit();
self.mainview.deinit(self.a); self.mainview.deinit(self.allocator);
self.message_filters.deinit(); self.message_filters.deinit();
self.input_listeners.deinit(); self.input_listeners.deinit();
if (self.frame_clock_running) if (self.frame_clock_running)
@ -177,7 +177,7 @@ fn deinit(self: *Self) void {
self.rdr.stop(); self.rdr.stop();
self.rdr.deinit(); self.rdr.deinit();
self.logger.deinit(); self.logger.deinit();
self.a.destroy(self); self.allocator.destroy(self);
} }
fn listen_sigwinch(self: *Self) tp.result { fn listen_sigwinch(self: *Self) tp.result {
@ -192,7 +192,7 @@ fn update_mouse_idle_timer(self: *Self) void {
t.deinit(); t.deinit();
self.mouse_idle_timer = null; self.mouse_idle_timer = null;
} }
self.mouse_idle_timer = tp.self_pid().delay_send_cancellable(self.a, "tui.mouse_idle_timer", delay, .{"MOUSE_IDLE"}) catch return; self.mouse_idle_timer = tp.self_pid().delay_send_cancellable(self.allocator, "tui.mouse_idle_timer", delay, .{"MOUSE_IDLE"}) catch return;
} }
fn receive(self: *Self, from: tp.pid_ref, m: tp.message) tp.result { fn receive(self: *Self, from: tp.pid_ref, m: tp.message) tp.result {
@ -542,14 +542,14 @@ pub fn refresh_hover(self: *Self) void {
} }
pub fn save_config(self: *const Self) !void { pub fn save_config(self: *const Self) !void {
try root.write_config(self.config, self.a); try root.write_config(self.config, self.allocator);
} }
fn enter_overlay_mode(self: *Self, mode: type) command.Result { fn enter_overlay_mode(self: *Self, mode: type) command.Result {
if (self.mini_mode) |_| try cmds.exit_mini_mode(self, .{}); if (self.mini_mode) |_| try cmds.exit_mini_mode(self, .{});
if (self.input_mode_outer) |_| try cmds.exit_overlay_mode(self, .{}); if (self.input_mode_outer) |_| try cmds.exit_overlay_mode(self, .{});
self.input_mode_outer = self.input_mode; self.input_mode_outer = self.input_mode;
self.input_mode = try mode.create(self.a); self.input_mode = try mode.create(self.allocator);
} }
const cmds = struct { const cmds = struct {
@ -627,24 +627,24 @@ const cmds = struct {
if (self.input_mode_outer) |_| try exit_overlay_mode(self, .{}); if (self.input_mode_outer) |_| try exit_overlay_mode(self, .{});
if (self.input_mode) |*m| m.deinit(); if (self.input_mode) |*m| m.deinit();
self.input_mode = if (std.mem.eql(u8, mode, "vim/normal")) self.input_mode = if (std.mem.eql(u8, mode, "vim/normal"))
try @import("mode/input/vim/normal.zig").create(self.a) try @import("mode/input/vim/normal.zig").create(self.allocator)
else if (std.mem.eql(u8, mode, "vim/insert")) else if (std.mem.eql(u8, mode, "vim/insert"))
try @import("mode/input/vim/insert.zig").create(self.a) try @import("mode/input/vim/insert.zig").create(self.allocator)
else if (std.mem.eql(u8, mode, "vim/visual")) else if (std.mem.eql(u8, mode, "vim/visual"))
try @import("mode/input/vim/visual.zig").create(self.a) try @import("mode/input/vim/visual.zig").create(self.allocator)
else if (std.mem.eql(u8, mode, "helix/normal")) else if (std.mem.eql(u8, mode, "helix/normal"))
try @import("mode/input/helix/normal.zig").create(self.a) try @import("mode/input/helix/normal.zig").create(self.allocator)
else if (std.mem.eql(u8, mode, "helix/insert")) else if (std.mem.eql(u8, mode, "helix/insert"))
try @import("mode/input/helix/insert.zig").create(self.a) try @import("mode/input/helix/insert.zig").create(self.allocator)
else if (std.mem.eql(u8, mode, "helix/select")) else if (std.mem.eql(u8, mode, "helix/select"))
try @import("mode/input/helix/select.zig").create(self.a) try @import("mode/input/helix/select.zig").create(self.allocator)
else if (std.mem.eql(u8, mode, "flow")) else if (std.mem.eql(u8, mode, "flow"))
try @import("mode/input/flow.zig").create(self.a) try @import("mode/input/flow.zig").create(self.allocator)
else if (std.mem.eql(u8, mode, "home")) else if (std.mem.eql(u8, mode, "home"))
try @import("mode/input/home.zig").create(self.a) try @import("mode/input/home.zig").create(self.allocator)
else ret: { else ret: {
self.logger.print("unknown mode {s}", .{mode}); self.logger.print("unknown mode {s}", .{mode});
break :ret try @import("mode/input/flow.zig").create(self.a); break :ret try @import("mode/input/flow.zig").create(self.allocator);
}; };
// self.logger.print("input mode: {s}", .{(self.input_mode orelse return).description}); // self.logger.print("input mode: {s}", .{(self.input_mode orelse return).description});
} }
@ -713,7 +713,7 @@ const cmds = struct {
self.input_mode_outer = null; self.input_mode_outer = null;
self.mini_mode = null; self.mini_mode = null;
} }
const mode_instance = try mode.create(self.a, ctx); const mode_instance = try mode.create(self.allocator, ctx);
self.input_mode = .{ self.input_mode = .{
.handler = mode_instance.handler(), .handler = mode_instance.handler(),
.name = mode_instance.name(), .name = mode_instance.name(),