refactor: change a -> allocator
This commit is contained in:
parent
ad58b1868d
commit
7b812d73ea
63 changed files with 896 additions and 896 deletions
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue