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

@ -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 = try a.create(Self);
const self = try allocator.create(Self);
var n = try Plane.init(&opts.pos.opts(@typeName(Self)), parent);
errdefer n.deinit();
self.* = .{
.a = a,
.allocator = allocator,
.parent = parent,
.plane = n,
.opts = opts,
};
self.opts.label = try self.a.dupe(u8, opts.label);
self.opts.label = try self.allocator.dupe(u8, opts.label);
return self;
}
pub fn create_widget(ctx_type: type, a: std.mem.Allocator, parent: Plane, opts: Options(ctx_type)) error{OutOfMemory}!Widget {
return Widget.to(try create(ctx_type, a, parent, opts));
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, allocator, parent, opts));
}
pub fn State(ctx_type: type) type {
return struct {
a: std.mem.Allocator,
allocator: std.mem.Allocator,
parent: Plane,
plane: Plane,
active: bool = false,
@ -77,10 +77,10 @@ pub fn State(ctx_type: type) type {
const Self = @This();
pub const Context = ctx_type;
pub fn deinit(self: *Self, a: std.mem.Allocator) void {
self.a.free(self.opts.label);
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
self.allocator.free(self.opts.label);
self.plane.deinit();
a.destroy(self);
allocator.destroy(self);
}
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);
}
pub fn empty(a: Allocator) !Self {
pub fn empty(allocator: Allocator) !Self {
const child: type = struct {};
const widget = try a.create(child);
const widget = try allocator.create(child);
widget.* = .{};
return .{
.ptr = widget,
@ -106,8 +106,8 @@ pub fn empty(a: Allocator) !Self {
.vtable = comptime &.{
.type_name = @typeName(child),
.deinit = struct {
pub fn deinit(ctx: *anyopaque, a_: Allocator) void {
return a_.destroy(@as(*child, @ptrCast(@alignCast(ctx))));
pub fn deinit(ctx: *anyopaque, allocator_: Allocator) void {
return allocator_.destroy(@as(*child, @ptrCast(@alignCast(ctx))));
}
}.deinit,
.send = struct {
@ -120,14 +120,14 @@ pub fn empty(a: Allocator) !Self {
}
pub const List = struct {
a: Allocator,
allocator: Allocator,
list: ArrayList(EventHandler),
recursion_check: bool = false,
pub fn init(a: Allocator) List {
pub fn init(allocator: Allocator) List {
return .{
.a = a,
.list = ArrayList(EventHandler).init(a),
.allocator = allocator,
.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 = try a.create(Self);
const self = try allocator.create(Self);
var n = try Plane.init(&opts.pos.opts(@typeName(Self)), parent);
errdefer n.deinit();
self.* = .{
.parent = parent,
.plane = n,
.opts = opts,
.label = std.ArrayList(u8).init(a),
.text = std.ArrayList(u8).init(a),
.label = std.ArrayList(u8).init(allocator),
.text = std.ArrayList(u8).init(allocator),
};
try self.label.appendSlice(self.opts.label);
self.opts.label = self.label.items;
@ -79,11 +79,11 @@ pub fn State(ctx_type: type) type {
const Self = @This();
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.label.deinit();
self.plane.deinit();
a.destroy(self);
allocator.destroy(self);
}
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) {
const self = try a.create(State(ctx_type));
const container = try WidgetList.createH(a, parent, @typeName(@This()), .dynamic);
pub fn create(ctx_type: type, allocator: std.mem.Allocator, parent: Widget, opts: Options(ctx_type)) !*State(ctx_type) {
const self = try allocator.create(State(ctx_type));
const container = try WidgetList.createH(allocator, parent, @typeName(@This()), .dynamic);
self.* = .{
.a = a,
.menu = try WidgetList.createV(a, container.widget(), @typeName(@This()), .dynamic),
.allocator = allocator,
.menu = try WidgetList.createV(allocator, container.widget(), @typeName(@This()), .dynamic),
.container = container,
.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,
};
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 {
return struct {
a: std.mem.Allocator,
allocator: std.mem.Allocator,
menu: *WidgetList,
container: *WidgetList,
container_widget: Widget,
@ -87,9 +87,9 @@ pub fn State(ctx_type: type) type {
const options_type = Options(ctx_type);
const button_type = Button.State(*Self);
pub fn deinit(self: *Self, a: std.mem.Allocator) void {
self.menu.deinit(a);
a.destroy(self);
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
self.menu.deinit(allocator);
allocator.destroy(self);
}
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 {
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,
.on_layout = self.opts.on_layout,
.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 {
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,
.on_layout = on_layout,
.label = label,
@ -125,7 +125,7 @@ pub fn State(ctx_type: type) type {
pub fn reset_items(self: *Self) void {
for (self.menu.widgets.items, 0..) |*w, i|
if (i >= self.header_count)
w.widget.deinit(self.a);
w.widget.deinit(self.allocator);
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 {
a: Allocator,
allocator: Allocator,
list: ArrayList(MessageFilter),
pub fn init(a: Allocator) List {
pub fn init(allocator: Allocator) List {
return .{
.a = a,
.list = ArrayList(MessageFilter).init(a),
.allocator = allocator,
.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 {
var sfa = std.heap.stackFallback(4096, self.a);
var sfa = std.heap.stackFallback(4096, self.allocator);
const a = sfa.get();
const buf = a.alloc(u8, m.buf.len) catch |e| return tp.exit_error(e, @errorReturnTrace());
defer a.free(buf);

View file

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

View file

@ -21,7 +21,7 @@ const WidgetState = struct {
plane: Plane,
parent: Plane,
a: Allocator,
allocator: Allocator,
widgets: ArrayList(WidgetState),
layout: Layout,
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,
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 {
const self: *Self = try a.create(Self);
self.* = try init(a, parent, name, .horizontal, layout_, Box{});
pub fn createH(allocator: Allocator, parent: Widget, name: [:0]const u8, layout_: Layout) !*Self {
const self: *Self = try allocator.create(Self);
self.* = try init(allocator, parent, name, .horizontal, layout_, Box{});
self.plane.hide();
return self;
}
pub fn createV(a: Allocator, parent: Widget, name: [:0]const u8, layout_: Layout) !*Self {
const self: *Self = try a.create(Self);
self.* = try init(a, parent, name, .vertical, layout_, Box{});
pub fn createV(allocator: Allocator, parent: Widget, name: [:0]const u8, layout_: Layout) !*Self {
const self: *Self = try allocator.create(Self);
self.* = try init(allocator, parent, name, .vertical, layout_, Box{});
self.plane.hide();
return self;
}
pub fn createBox(a: Allocator, parent: Widget, name: [:0]const u8, dir: Direction, layout_: Layout, box: Box) !*Self {
const self: *Self = try a.create(Self);
self.* = try init(a, parent, name, dir, layout_, box);
pub fn createBox(allocator: Allocator, parent: Widget, name: [:0]const u8, dir: Direction, layout_: Layout, box: Box) !*Self {
const self: *Self = try allocator.create(Self);
self.* = try init(allocator, parent, name, dir, layout_, box);
self.plane.hide();
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 .{
.plane = try Plane.init(&box.opts(name), parent.plane.*),
.parent = parent.plane.*,
.a = a,
.widgets = ArrayList(WidgetState).init(a),
.allocator = allocator,
.widgets = ArrayList(WidgetState).init(allocator),
.layout = layout_,
.direction = dir,
};
@ -71,12 +71,12 @@ pub fn layout(self: *Self) Widget.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|
w.widget.deinit(self.a);
w.widget.deinit(self.allocator);
self.widgets.deinit();
self.plane.deinit();
a.destroy(self);
allocator.destroy(self);
}
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 {
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 {
@ -108,7 +108,7 @@ pub fn swap(self: *Self, n: usize, w: Widget) Widget {
pub fn replace(self: *Self, n: usize, w: Widget) void {
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 {

View file

@ -8,19 +8,19 @@ const Widget = @import("Widget.zig");
const Self = @This();
a: Allocator,
allocator: Allocator,
widgets: ArrayList(Widget),
pub fn init(a_: Allocator) Self {
pub fn init(allocator: Allocator) Self {
return .{
.a = a_,
.widgets = ArrayList(Widget).init(a_),
.allocator = allocator,
.widgets = ArrayList(Widget).init(allocator),
};
}
pub fn deinit(self: *Self) void {
for (self.widgets.items) |*widget|
widget.deinit(self.a);
widget.deinit(self.allocator);
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 {
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 {

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 ed = @import("editor.zig");
a: Allocator,
allocator: Allocator,
plane: Plane,
parent: Widget,
@ -40,10 +40,10 @@ const Self = @This();
const Kind = enum { insert, modified, delete };
const Symbol = struct { kind: Kind, line: usize };
pub fn create(a: Allocator, parent: Widget, event_source: Widget, editor: *ed.Editor) !Widget {
const self: *Self = try a.create(Self);
pub fn create(allocator: Allocator, parent: Widget, event_source: Widget, editor: *ed.Editor) !Widget {
const self: *Self = try allocator.create(Self);
self.* = .{
.a = a,
.allocator = allocator,
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent.plane.*),
.parent = parent,
.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,
.editor = editor,
.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 event_source.subscribe(EventHandler.bind(self, handle_event));
@ -62,12 +62,12 @@ pub fn widget(self: *Self) Widget {
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.deinit();
tui.current().message_filters.remove_ptr(self);
self.plane.deinit();
a.destroy(self);
allocator.destroy(self);
}
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);
}
pub fn deinit(self: *Self, a: Allocator) void {
pub fn deinit(self: *Self, allocator: Allocator) void {
self.plane.deinit();
self.commands.deinit();
a.destroy(self);
allocator.destroy(self);
}
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 fonts = @import("fonts.zig");
a: std.mem.Allocator,
allocator: std.mem.Allocator,
plane: Plane,
parent: Plane,
fire: ?Fire = null,
@ -24,17 +24,17 @@ menu: *Menu.State(*Self),
const Self = @This();
pub fn create(a: std.mem.Allocator, parent: Widget) !Widget {
const self: *Self = try a.create(Self);
pub fn create(allocator: std.mem.Allocator, parent: Widget) !Widget {
const self: *Self = try allocator.create(Self);
var n = try Plane.init(&(Widget.Box{}).opts("editor"), parent.plane.*);
errdefer n.deinit();
const w = Widget.to(self);
self.* = .{
.a = a,
.allocator = allocator,
.parent = parent.plane.*,
.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.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;
}
pub fn deinit(self: *Self, a: std.mem.Allocator) void {
self.menu.deinit(a);
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
self.menu.deinit(allocator);
self.commands.deinit();
self.plane.deinit();
if (self.fire) |*fire| fire.deinit();
a.destroy(self);
allocator.destroy(self);
}
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;
if (self.fire) |*fire| {
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: {
fire.deinit();
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 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 FIRE_H = @as(u16, @intCast(pos.h)) * 2;
const FIRE_W = @as(u16, @intCast(pos.w));
var self: Fire = .{
.allocator = a,
.allocator = allocator,
.plane = plane,
.prng = std.Random.DefaultPrng.init(blk: {
var seed: u64 = undefined;
@ -255,7 +255,7 @@ const Fire = struct {
.FIRE_W = FIRE_W,
.FIRE_SZ = FIRE_H * 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;

View file

@ -15,7 +15,7 @@ const EventHandler = @import("EventHandler.zig");
pub const name = "inputview";
a: Allocator,
allocator: Allocator,
parent: Plane,
plane: Plane,
last_count: u64 = 0,
@ -30,27 +30,27 @@ const Entry = struct {
};
const Buffer = ArrayList(Entry);
pub fn create(a: Allocator, parent: Plane) !Widget {
const self: *Self = try a.create(Self);
pub fn create(allocator: Allocator, parent: Plane) !Widget {
const self: *Self = try allocator.create(Self);
var n = try Plane.init(&(Widget.Box{}).opts_vscroll(@typeName(Self)), parent);
errdefer n.deinit();
self.* = .{
.a = a,
.allocator = allocator,
.parent = parent,
.plane = n,
.buffer = Buffer.init(a),
.buffer = Buffer.init(allocator),
};
try tui.current().input_listeners.add(EventHandler.bind(self, listen));
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);
for (self.buffer.items) |item|
self.buffer.allocator.free(item.json);
self.buffer.deinit();
self.plane.deinit();
a.destroy(self);
allocator.destroy(self);
}
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()).* = .{
.time = ts,
.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();
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| {
const self: *Self = try a.create(Self);
const self: *Self = try allocator.create(Self);
self.* = .{
.plane = try Plane.init(&(Widget.Box{}).opts_vscroll(name), parent),
.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));
@ -42,11 +42,11 @@ pub fn create(a: Allocator, parent: Plane) !Widget {
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);
tui.current().message_filters.remove_ptr(self);
self.plane.deinit();
a.destroy(self);
allocator.destroy(self);
}
pub fn render(self: *Self, theme: *const Widget.Theme) bool {

View file

@ -39,15 +39,15 @@ const Level = enum {
err,
};
pub fn create(a: Allocator, parent: Plane) !Widget {
const self: *Self = try a.create(Self);
pub fn create(allocator: Allocator, parent: Plane) !Widget {
const self: *Self = try allocator.create(Self);
self.* = .{ .plane = try Plane.init(&(Widget.Box{}).opts(name), parent) };
return Widget.to(self);
}
pub fn deinit(self: *Self, a: Allocator) void {
pub fn deinit(self: *Self, allocator: Allocator) void {
self.plane.deinit();
a.destroy(self);
allocator.destroy(self);
}
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");
}
pub fn init(a: Allocator) void {
pub fn init(allocator: Allocator) void {
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 Commands = command.Collection(cmds);
a: std.mem.Allocator,
allocator: std.mem.Allocator,
plane: Plane,
widgets: *WidgetList,
widgets_widget: Widget,
@ -61,30 +61,30 @@ const FileListType = enum {
find_in_files,
};
pub fn create(a: std.mem.Allocator) !Widget {
const self = try a.create(Self);
pub fn create(allocator: std.mem.Allocator) !Widget {
const self = try allocator.create(Self);
self.* = .{
.a = a,
.allocator = allocator,
.plane = tui.current().stdplane(),
.widgets = undefined,
.widgets_widget = undefined,
.floating_views = WidgetStack.init(a),
.floating_views = WidgetStack.init(allocator),
.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,
};
try self.commands.init(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_widget = widgets.widget();
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;
}
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) {
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"))
self.toggle_inputview_async();
@ -93,14 +93,14 @@ pub fn create(a: std.mem.Allocator) !Widget {
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.clear_file_stack();
self.file_stack.deinit();
self.commands.deinit();
self.widgets.deinit(a);
self.widgets.deinit(allocator);
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 {
@ -180,12 +180,12 @@ fn toggle_panel_view(self: *Self, view: anytype, enable_only: bool) !void {
}
}
} else {
try panels.add(try view.create(self.a, self.widgets.plane));
try panels.add(try view.create(self.allocator, self.widgets.plane));
}
} 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 panels.add(try view.create(self.a, self.widgets.plane));
try panels.add(try view.create(self.allocator, self.widgets.plane));
self.panels = panels;
}
tui.current().resize();
@ -211,7 +211,7 @@ fn toggle_view(self: *Self, view: anytype) !void {
if (self.widgets.get(@typeName(view))) |w| {
self.widgets.remove(w.*);
} 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();
}
@ -269,8 +269,8 @@ const cmds = struct {
tui.current().rdr.set_terminal_working_directory(project);
if (self.top_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| {
defer self.a.free(file_path);
if (try project_manager.request_most_recent_file(self.allocator)) |file_path| {
defer self.allocator.free(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 (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);
} else self.show_home_async();
self.editor = null;
@ -537,7 +537,7 @@ pub fn handle_editor_event(self: *Self, _: tp.pid_ref, m: tp.message) tp.result
sel.normalize();
if (sel.end.row - sel.begin.row > ed.max_match_lines)
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)
return self.clear_auto_find(editor);
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...", .{});
const find_f = ripgrep.find_in_files;
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();
}
@ -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 {
if (self.last_match_text) |old|
self.a.free(old);
self.allocator.free(old);
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 {
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 {};
var editor_widget = try ed.create(self.a, Widget.to(self));
errdefer editor_widget.deinit(self.a);
var editor_widget = try ed.create(self.allocator, Widget.to(self));
errdefer editor_widget.deinit(self.allocator);
if (editor_widget.get("editor")) |editor| {
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");
@ -647,15 +647,15 @@ fn show_home_async(_: *Self) void {
fn create_home(self: *Self) !void {
tui.reset_drag_context();
if (self.editor) |_| return;
var home_widget = try home.create(self.a, Widget.to(self));
errdefer home_widget.deinit(self.a);
var home_widget = try home.create(self.allocator, Widget.to(self));
errdefer home_widget.deinit(self.allocator);
self.widgets.replace(self.view_widget_idx, home_widget);
tui.current().resize();
}
fn write_restore_info(self: *Self) void {
if (self.editor) |editor| {
var sfa = std.heap.stackFallback(512, self.a);
var sfa = std.heap.stackFallback(512, self.allocator);
const a = sfa.get();
var meta = std.ArrayList(u8).init(a);
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 });
defer file.close();
const stat = try file.stat();
var buf = try self.a.alloc(u8, @intCast(stat.size));
defer self.a.free(buf);
var buf = try self.allocator.alloc(u8, @intCast(stat.size));
defer self.allocator.free(buf);
const size = try file.readAll(buf);
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 {
for (self.file_stack.items, 0..) |file_path_, i|
if (std.mem.eql(u8, file_path, file_path_))
self.a.free(self.file_stack.orderedRemove(i));
(try self.file_stack.addOne()).* = try self.a.dupe(u8, file_path);
self.allocator.free(self.file_stack.orderedRemove(i));
(try self.file_stack.addOne()).* = try self.allocator.dupe(u8, file_path);
}
fn pop_file_stack(self: *Self, closed: ?[]const u8) ?[]const u8 {
if (closed) |file_path|
for (self.file_stack.items, 0..) |file_path_, i|
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();
}
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();
}

View file

@ -18,16 +18,16 @@ const eql = @import("std").mem.eql;
const Self = @This();
const input_buffer_size = 1024;
a: Allocator,
allocator: Allocator,
input: ArrayList(u8),
last_cmd: []const u8 = "",
leader: ?struct { keypress: u32, modifiers: u32 } = null,
pub fn create(a: Allocator) !tui.Mode {
const self: *Self = try a.create(Self);
pub fn create(allocator: Allocator) !tui.Mode {
const self: *Self = try allocator.create(Self);
self.* = .{
.a = a,
.input = try ArrayList(u8).initCapacity(a, input_buffer_size),
.allocator = allocator,
.input = try ArrayList(u8).initCapacity(allocator, input_buffer_size),
};
return .{
.handler = EventHandler.to_owned(self),
@ -39,7 +39,7 @@ pub fn create(a: Allocator) !tui.Mode {
pub fn deinit(self: *Self) void {
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 {

View file

@ -17,17 +17,17 @@ const eql = @import("std").mem.eql;
const Self = @This();
const input_buffer_size = 1024;
a: Allocator,
allocator: Allocator,
input: ArrayList(u8),
last_cmd: []const u8 = "",
leader: ?struct { keypress: u32, modifiers: u32 } = null,
commands: Commands = undefined,
pub fn create(a: Allocator) !tui.Mode {
const self: *Self = try a.create(Self);
pub fn create(allocator: Allocator) !tui.Mode {
const self: *Self = try allocator.create(Self);
self.* = .{
.a = a,
.input = try ArrayList(u8).initCapacity(a, input_buffer_size),
.allocator = allocator,
.input = try ArrayList(u8).initCapacity(allocator, input_buffer_size),
};
try self.commands.init(self);
return .{
@ -42,7 +42,7 @@ pub fn create(a: Allocator) !tui.Mode {
pub fn deinit(self: *Self) void {
self.commands.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 {

View file

@ -17,18 +17,18 @@ const eql = @import("std").mem.eql;
const Self = @This();
const input_buffer_size = 1024;
a: Allocator,
allocator: Allocator,
input: ArrayList(u8),
last_cmd: []const u8 = "",
leader: ?struct { keypress: u32, modifiers: u32 } = null,
count: usize = 0,
commands: Commands = undefined,
pub fn create(a: Allocator) !tui.Mode {
const self: *Self = try a.create(Self);
pub fn create(allocator: Allocator) !tui.Mode {
const self: *Self = try allocator.create(Self);
self.* = .{
.a = a,
.input = try ArrayList(u8).initCapacity(a, input_buffer_size),
.allocator = allocator,
.input = try ArrayList(u8).initCapacity(allocator, input_buffer_size),
};
try self.commands.init(self);
return .{
@ -44,7 +44,7 @@ pub fn create(a: Allocator) !tui.Mode {
pub fn deinit(self: *Self) void {
self.commands.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 {

View file

@ -17,18 +17,18 @@ const eql = @import("std").mem.eql;
const Self = @This();
const input_buffer_size = 1024;
a: Allocator,
allocator: Allocator,
input: ArrayList(u8),
last_cmd: []const u8 = "",
leader: ?struct { keypress: u32, modifiers: u32 } = null,
count: usize = 0,
commands: Commands = undefined,
pub fn create(a: Allocator) !tui.Mode {
const self: *Self = try a.create(Self);
pub fn create(allocator: Allocator) !tui.Mode {
const self: *Self = try allocator.create(Self);
self.* = .{
.a = a,
.input = try ArrayList(u8).initCapacity(a, input_buffer_size),
.allocator = allocator,
.input = try ArrayList(u8).initCapacity(allocator, input_buffer_size),
};
try self.commands.init(self);
return .{
@ -44,7 +44,7 @@ pub fn create(a: Allocator) !tui.Mode {
pub fn deinit(self: *Self) void {
self.commands.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 {

View file

@ -12,14 +12,14 @@ const EventHandler = @import("../../EventHandler.zig");
const Self = @This();
a: std.mem.Allocator,
allocator: std.mem.Allocator,
f: usize = 0,
leader: ?struct { keypress: u32, modifiers: u32 } = null,
pub fn create(a: std.mem.Allocator) !tui.Mode {
const self: *Self = try a.create(Self);
pub fn create(allocator: std.mem.Allocator) !tui.Mode {
const self: *Self = try allocator.create(Self);
self.* = .{
.a = a,
.allocator = allocator,
};
return .{
.handler = EventHandler.to_owned(self),
@ -30,7 +30,7 @@ pub fn create(a: std.mem.Allocator) !tui.Mode {
}
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 {

View file

@ -17,17 +17,17 @@ const eql = @import("std").mem.eql;
const Self = @This();
const input_buffer_size = 1024;
a: Allocator,
allocator: Allocator,
input: ArrayList(u8),
last_cmd: []const u8 = "",
leader: ?struct { keypress: u32, modifiers: u32 } = null,
commands: Commands = undefined,
pub fn create(a: Allocator) !tui.Mode {
const self: *Self = try a.create(Self);
pub fn create(allocator: Allocator) !tui.Mode {
const self: *Self = try allocator.create(Self);
self.* = .{
.a = a,
.input = try ArrayList(u8).initCapacity(a, input_buffer_size),
.allocator = allocator,
.input = try ArrayList(u8).initCapacity(allocator, input_buffer_size),
};
try self.commands.init(self);
return .{
@ -42,7 +42,7 @@ pub fn create(a: Allocator) !tui.Mode {
pub fn deinit(self: *Self) void {
self.commands.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 {

View file

@ -17,18 +17,18 @@ const eql = @import("std").mem.eql;
const Self = @This();
const input_buffer_size = 1024;
a: Allocator,
allocator: Allocator,
input: ArrayList(u8),
last_cmd: []const u8 = "",
leader: ?struct { keypress: u32, modifiers: u32 } = null,
count: usize = 0,
commands: Commands = undefined,
pub fn create(a: Allocator) !tui.Mode {
const self: *Self = try a.create(Self);
pub fn create(allocator: Allocator) !tui.Mode {
const self: *Self = try allocator.create(Self);
self.* = .{
.a = a,
.input = try ArrayList(u8).initCapacity(a, input_buffer_size),
.allocator = allocator,
.input = try ArrayList(u8).initCapacity(allocator, input_buffer_size),
};
try self.commands.init(self);
return .{
@ -44,7 +44,7 @@ pub fn create(a: Allocator) !tui.Mode {
pub fn deinit(self: *Self) void {
self.commands.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 {

View file

@ -17,18 +17,18 @@ const eql = @import("std").mem.eql;
const Self = @This();
const input_buffer_size = 1024;
a: Allocator,
allocator: Allocator,
input: ArrayList(u8),
last_cmd: []const u8 = "",
leader: ?struct { keypress: u32, modifiers: u32 } = null,
count: usize = 0,
commands: Commands = undefined,
pub fn create(a: Allocator) !tui.Mode {
const self: *Self = try a.create(Self);
pub fn create(allocator: Allocator) !tui.Mode {
const self: *Self = try allocator.create(Self);
self.* = .{
.a = a,
.input = try ArrayList(u8).initCapacity(a, input_buffer_size),
.allocator = allocator,
.input = try ArrayList(u8).initCapacity(allocator, input_buffer_size),
};
try self.commands.init(self);
return .{
@ -44,7 +44,7 @@ pub fn create(a: Allocator) !tui.Mode {
pub fn deinit(self: *Self) void {
self.commands.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 {

View file

@ -19,7 +19,7 @@ const max_complete_paths = 1024;
pub fn Create(options: type) type {
return struct {
a: std.mem.Allocator,
allocator: std.mem.Allocator,
file_path: std.ArrayList(u8),
query: std.ArrayList(u8),
match: std.ArrayList(u8),
@ -34,14 +34,14 @@ pub fn Create(options: type) type {
type: enum { dir, file, link },
};
pub fn create(a: std.mem.Allocator, _: command.Context) !*Self {
const self: *Self = try a.create(Self);
pub fn create(allocator: std.mem.Allocator, _: command.Context) !*Self {
const self: *Self = try allocator.create(Self);
self.* = .{
.a = a,
.file_path = std.ArrayList(u8).init(a),
.query = std.ArrayList(u8).init(a),
.match = std.ArrayList(u8).init(a),
.entries = std.ArrayList(Entry).init(a),
.allocator = allocator,
.file_path = std.ArrayList(u8).init(allocator),
.query = std.ArrayList(u8).init(allocator),
.match = std.ArrayList(u8).init(allocator),
.entries = std.ArrayList(Entry).init(allocator),
};
try tui.current().message_filters.add(MessageFilter.bind(self, receive_path_entry));
try options.load_entries(self);
@ -57,7 +57,7 @@ pub fn Create(options: type) type {
self.match.deinit();
self.query.deinit();
self.file_path.deinit();
self.a.destroy(self);
self.allocator.destroy(self);
}
pub fn handler(self: *Self) EventHandler {
@ -171,7 +171,7 @@ pub fn Create(options: type) type {
}
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();
}
@ -246,11 +246,11 @@ pub fn Create(options: type) type {
var path: []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) })) {
(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) })) {
(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) })) {
(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 {
log.logger("file_browser").err("receive", tp.unexpected(m));
}

View file

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

View file

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

View file

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

View file

@ -17,7 +17,7 @@ const fmt = @import("std").fmt;
const Self = @This();
a: Allocator,
allocator: Allocator,
key: [6]u8 = undefined,
direction: Direction,
operation: Operation,
@ -32,13 +32,13 @@ const Operation = enum {
select,
};
pub fn create(a: Allocator, ctx: command.Context) !*Self {
pub fn create(allocator: Allocator, ctx: command.Context) !*Self {
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;
_ = 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.* = .{
.a = a,
.allocator = allocator,
.direction = if (right) .right else .left,
.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 {
self.a.destroy(self);
self.allocator.destroy(self);
}
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|
try self.file_path.appendSlice(old_path[0 .. pos + 1]);
if (editor.get_primary().selection) |sel| ret: {
const text = editor.get_selection(sel, self.a) catch break :ret;
defer self.a.free(text);
const text = editor.get_selection(sel, self.allocator) catch break :ret;
defer self.allocator.free(text);
if (!(text.len > 2 and std.mem.eql(u8, text[0..2], "..")))
self.file_path.clearRetainingCapacity();
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| {
try self.file_path.appendSlice(editor.file_path orelse "");
if (editor.get_primary().selection) |sel| ret: {
const text = editor.get_selection(sel, self.a) catch break :ret;
defer self.a.free(text);
const text = editor.get_selection(sel, self.allocator) catch break :ret;
defer self.allocator.free(text);
if (!(text.len > 2 and std.mem.eql(u8, text[0..2], "..")))
self.file_path.clearRetainingCapacity();
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 {
var value = std.ArrayList(u8).init(palette.a);
var value = std.ArrayList(u8).init(palette.allocator);
defer value.deinit();
const writer = value.writer();
try cbor.writeValue(writer, entry.name);

View file

@ -25,7 +25,7 @@ const mainview = @import("../../mainview.zig");
const Self = @This();
const max_recent_files: usize = 25;
a: std.mem.Allocator,
allocator: std.mem.Allocator,
f: usize = 0,
menu: *Menu.State(*Self),
inputbox: *InputBox.State(*Self),
@ -36,18 +36,18 @@ need_select_first: bool = true,
longest: usize = 0,
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 self: *Self = try a.create(Self);
const self: *Self = try allocator.create(Self);
self.* = .{
.a = a,
.menu = try Menu.create(*Self, a, tui.current().mainview, .{
.allocator = allocator,
.menu = try Menu.create(*Self, allocator, tui.current().mainview, .{
.ctx = self,
.on_render = on_render_menu,
.on_resize = on_resize_menu,
}),
.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,
.label = "Search files by name",
}))).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|
mv.floating_views.remove(self.menu.container_widget);
self.logger.deinit();
self.a.destroy(self);
self.allocator.destroy(self);
}
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 {
var label = std.ArrayList(u8).init(self.a);
var label = std.ArrayList(u8).init(self.allocator);
defer label.deinit();
const writer = label.writer();
try cbor.writeValue(writer, file_name);

View file

@ -24,24 +24,24 @@ pub const Match = struct {
pub fn deinit(palette: *Type) void {
for (palette.entries.items) |entry|
palette.a.free(entry.name);
palette.allocator.free(entry.name);
}
pub fn load_entries(palette: *Type) !void {
const rsp = try project_manager.request_recent_projects(palette.a);
defer palette.a.free(rsp.buf);
const rsp = try project_manager.request_recent_projects(palette.allocator);
defer palette.allocator.free(rsp.buf);
var iter: []const u8 = rsp.buf;
var len = try cbor.decodeArrayHeader(&iter);
while (len > 0) : (len -= 1) {
var name_: []const u8 = undefined;
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;
}
}
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();
const writer = value.writer();
try cbor.writeValue(writer, entry.name);

View file

@ -26,7 +26,7 @@ const max_menu_width = 80;
pub fn Create(options: type) type {
return struct {
a: std.mem.Allocator,
allocator: std.mem.Allocator,
menu: *Menu.State(*Self),
inputbox: *InputBox.State(*Self),
logger: log.Logger,
@ -47,12 +47,12 @@ pub fn Create(options: type) type {
pub const MenuState = 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 self: *Self = try a.create(Self);
const self: *Self = try allocator.create(Self);
self.* = .{
.a = a,
.menu = try Menu.create(*Self, a, tui.current().mainview, .{
.allocator = allocator,
.menu = try Menu.create(*Self, allocator, tui.current().mainview, .{
.ctx = self,
.on_render = on_render_menu,
.on_resize = on_resize_menu,
@ -61,13 +61,13 @@ pub fn Create(options: type) type {
.on_click5 = mouse_click_button5,
}),
.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,
.label = options.label,
}))).dynamic_cast(InputBox.State(*Self)) orelse unreachable,
.hints = if (tui.current().input_mode) |m| m.keybind_hints else null,
.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;
if (self.hints) |hints| {
@ -96,7 +96,7 @@ pub fn Create(options: type) type {
if (tui.current().mainview.dynamic_cast(mainview)) |mv|
mv.floating_views.remove(self.menu.container_widget);
self.logger.deinit();
self.a.destroy(self);
self.allocator.destroy(self);
}
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 {
var searcher = try fuzzig.Ascii.init(
self.a,
self.allocator,
self.longest, // haystack max size
self.longest, // needle max size
.{ .case_sensitive = false },
@ -338,7 +338,7 @@ pub fn Create(options: type) type {
matches: []const usize,
};
var matches = std.ArrayList(Match).init(self.a);
var matches = std.ArrayList(Match).init(self.allocator);
for (self.entries.items) |*entry| {
const match = searcher.scoreMatches(entry.name, query);
@ -346,7 +346,7 @@ pub fn Create(options: type) type {
(try matches.addOne()).* = .{
.entry = entry,
.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;

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 {
var value = std.ArrayList(u8).init(palette.a);
var value = std.ArrayList(u8).init(palette.allocator);
defer value.deinit();
const writer = value.writer();
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();
pub fn create(a: Allocator, parent: Widget, event_source: ?Widget, event_sink: EventHandler) !Widget {
const self: *Self = try a.create(Self);
pub fn create(allocator: Allocator, parent: Widget, event_source: ?Widget, event_sink: EventHandler) !Widget {
const self: *Self = try allocator.create(Self);
self.* = .{
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent.plane.*),
.event_sink = event_sink,
@ -44,9 +44,9 @@ pub fn widget(self: *Self) Widget {
return Widget.to(self);
}
pub fn deinit(self: *Self, a: Allocator) void {
pub fn deinit(self: *Self, allocator: Allocator) void {
self.plane.deinit();
a.destroy(self);
allocator.destroy(self);
}
pub fn layout(_: *Self) Widget.Layout {

View file

@ -9,13 +9,13 @@ const Self = @This();
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 {
var w = try WidgetList.createH(a, parent, "statusbar", .{ .static = 1 });
pub fn create(allocator: std.mem.Allocator, parent: Widget, config: []const u8, style: Style, event_handler: ?Widget.EventHandler) !Widget {
var w = try WidgetList.createH(allocator, parent, "statusbar", .{ .static = 1 });
if (style == .grip) w.after_render = render_grip;
w.ctx = w;
var it = std.mem.splitScalar(u8, config, ' ');
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();
}

View file

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

View file

@ -26,22 +26,22 @@ const Level = enum {
err,
};
pub fn create(a: 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());
pub fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
var env = std.process.getEnvMap(allocator) catch |e| return tp.exit_error(e, @errorReturnTrace());
defer env.deinit();
const self: *Self = try a.create(Self);
const self: *Self = try allocator.create(Self);
self.* = .{
.allocator = a,
.allocator = allocator,
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
.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));
self.update_tick_timer(.init);
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);
if (self.tick_timer) |*t| {
t.cancel() catch {};
@ -50,7 +50,7 @@ pub fn deinit(self: *Self, a: std.mem.Allocator) void {
}
self.tz.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 {

View file

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

View file

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

View file

@ -31,10 +31,10 @@ const Self = @This();
const idle_msg = "🐶";
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");
if (frame_rate == 0) frame_rate = 60;
const self: *Self = try a.create(Self);
const self: *Self = try allocator.create(Self);
self.* = .{
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
.wipe_after_frames = @divTrunc(frame_rate, 2),
@ -47,10 +47,10 @@ pub fn widget(self: *Self) Widget {
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);
self.plane.deinit();
a.destroy(self);
allocator.destroy(self);
}
pub fn layout(_: *Self) Widget.Layout {

View file

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

View file

@ -26,20 +26,20 @@ const Level = enum {
err,
};
pub fn create(a: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
const self: *Self = try a.create(Self);
pub fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
const self: *Self = try allocator.create(Self);
self.* = .{
.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,
};
logview.init(a);
logview.init(allocator);
try tui.current().message_filters.add(MessageFilter.bind(self, receive_log));
try log.subscribe();
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| {
t.cancel() catch {};
t.deinit();
@ -49,7 +49,7 @@ pub fn deinit(self: *Self, a: std.mem.Allocator) void {
log.unsubscribe() catch {};
tui.current().message_filters.remove_ptr(self);
self.plane.deinit();
a.destroy(self);
allocator.destroy(self);
}
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 CreateError = @import("widget.zig").CreateError;
pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!Widget {
return Button.create_widget(void, a, parent, .{
pub fn create(allocator: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!Widget {
return Button.create_widget(void, allocator, parent, .{
.ctx = {},
.label = tui.get_mode(),
.on_click = on_click,

View file

@ -23,8 +23,8 @@ const Self = @This();
pub const width = 5;
pub fn create(a: Allocator, parent: Plane, _: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
const self: *Self = try a.create(Self);
pub fn create(allocator: Allocator, parent: Plane, _: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
const self: *Self = try allocator.create(Self);
self.* = .{
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
};
@ -36,10 +36,10 @@ pub fn widget(self: *Self) Widget {
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);
self.plane.deinit();
a.destroy(self);
allocator.destroy(self);
}
pub fn layout(_: *Self) Widget.Layout {

View file

@ -19,8 +19,8 @@ on_event: ?Widget.EventHandler,
const Self = @This();
pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
const self: *Self = try a.create(Self);
pub fn create(allocator: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
const self: *Self = try allocator.create(Self);
self.* = .{
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
.on_event = event_handler,
@ -28,9 +28,9 @@ pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler)
return Widget.to(self);
}
pub fn deinit(self: *Self, a: Allocator) void {
pub fn deinit(self: *Self, allocator: Allocator) void {
self.plane.deinit();
a.destroy(self);
allocator.destroy(self);
}
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 },
});
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;
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 maxInt = std.math.maxInt;
a: Allocator,
allocator: Allocator,
rdr: renderer,
config: config,
frame_time: usize, // in microseconds
@ -68,30 +68,30 @@ const Self = @This();
const Receiver = tp.Receiver(*Self);
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 {
return try ctx.spawn_link(StartArgs{ .a = a }, start, "tui", eh, env);
pub fn spawn(allocator: Allocator, ctx: *tp.context, eh: anytype, env: ?*const tp.env) !tp.pid {
return try ctx.spawn_link(StartArgs{ .allocator = allocator }, start, "tui", eh, env);
}
fn start(args: StartArgs) tp.result {
_ = 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();
tp.receive(&self.receiver);
}
fn init(a: Allocator) !*Self {
var self = try a.create(Self);
fn init(allocator: Allocator) !*Self {
var self = try allocator.create(Self);
var conf_buf: ?[]const u8 = null;
var conf = root.read_config(a, &conf_buf);
defer if (conf_buf) |buf| a.free(buf);
var conf = root.read_config(allocator, &conf_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");
conf.theme = theme.name;
conf.input_mode = try a.dupe(u8, conf.input_mode);
conf.top_bar = try a.dupe(u8, conf.top_bar);
conf.bottom_bar = try a.dupe(u8, conf.bottom_bar);
conf.input_mode = try allocator.dupe(u8, conf.input_mode);
conf.top_bar = try allocator.dupe(u8, conf.top_bar);
conf.bottom_bar = try allocator.dupe(u8, conf.bottom_bar);
const frame_rate: usize = @intCast(tp.env.get().num("frame-rate"));
if (frame_rate != 0)
@ -100,17 +100,17 @@ fn init(a: Allocator) !*Self {
const frame_clock = try tp.metronome.init(frame_time);
self.* = .{
.a = a,
.allocator = allocator,
.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_clock = frame_clock,
.frame_clock_running = true,
.receiver = Receiver.init(receive, self),
.mainview = undefined,
.message_filters = MessageFilter.List.init(a),
.message_filters = MessageFilter.List.init(allocator),
.input_mode = null,
.input_listeners = EventHandler.List.init(a),
.input_listeners = EventHandler.List.init(allocator),
.logger = log.logger("tui"),
.init_timer = try tp.timeout.init_ms(init_delay, tp.message.fmt(.{"init"})),
.theme = theme,
@ -131,13 +131,13 @@ fn init(a: Allocator) !*Self {
errdefer self.deinit();
switch (builtin.os.tag) {
.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 => {
try self.listen_sigwinch();
},
}
self.mainview = try mainview.create(a);
self.mainview = try mainview.create(allocator);
self.resize();
self.set_terminal_style();
try self.rdr.render();
@ -167,7 +167,7 @@ fn deinit(self: *Self) void {
}
if (self.input_mode) |*m| m.deinit();
self.commands.deinit();
self.mainview.deinit(self.a);
self.mainview.deinit(self.allocator);
self.message_filters.deinit();
self.input_listeners.deinit();
if (self.frame_clock_running)
@ -177,7 +177,7 @@ fn deinit(self: *Self) void {
self.rdr.stop();
self.rdr.deinit();
self.logger.deinit();
self.a.destroy(self);
self.allocator.destroy(self);
}
fn listen_sigwinch(self: *Self) tp.result {
@ -192,7 +192,7 @@ fn update_mouse_idle_timer(self: *Self) void {
t.deinit();
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 {
@ -542,14 +542,14 @@ pub fn refresh_hover(self: *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 {
if (self.mini_mode) |_| try cmds.exit_mini_mode(self, .{});
if (self.input_mode_outer) |_| try cmds.exit_overlay_mode(self, .{});
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 {
@ -627,24 +627,24 @@ const cmds = struct {
if (self.input_mode_outer) |_| try exit_overlay_mode(self, .{});
if (self.input_mode) |*m| m.deinit();
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"))
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"))
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"))
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"))
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"))
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"))
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"))
try @import("mode/input/home.zig").create(self.a)
try @import("mode/input/home.zig").create(self.allocator)
else ret: {
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});
}
@ -713,7 +713,7 @@ const cmds = struct {
self.input_mode_outer = 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 = .{
.handler = mode_instance.handler(),
.name = mode_instance.name(),