refactor: improve capsulation and safety of tui module public api

This commit is contained in:
CJ van den Berg 2025-01-23 16:45:04 +01:00
parent 4145460012
commit 1d947ab499
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
28 changed files with 239 additions and 198 deletions

View file

@ -44,7 +44,7 @@ pub fn Create(options: type) type {
.entries = std.ArrayList(Entry).init(allocator),
};
try self.commands.init(self);
try tui.current().message_filters.add(MessageFilter.bind(self, receive_path_entry));
try tui.message_filters().add(MessageFilter.bind(self, receive_path_entry));
try options.load_entries(self);
if (@hasDecl(options, "restore_state"))
options.restore_state(self) catch {};
@ -57,7 +57,7 @@ pub fn Create(options: type) type {
pub fn deinit(self: *Self) void {
self.commands.deinit();
tui.current().message_filters.remove_ptr(self);
tui.message_filters().remove_ptr(self);
self.clear_entries();
self.entries.deinit();
self.match.deinit();
@ -113,7 +113,7 @@ pub fn Create(options: type) type {
} else {
try self.file_path.appendSlice(self.query.items);
}
if (tui.current().mini_mode) |*mini_mode| {
if (tui.mini_mode()) |mini_mode| {
mini_mode.text = self.file_path.items;
mini_mode.cursor = tui.egc_chunk_width(self.file_path.items, 0, 8);
}
@ -137,7 +137,7 @@ pub fn Create(options: type) type {
fn process_project_manager(self: *Self, m: tp.message) MessageFilter.Error!void {
defer {
if (tui.current().mini_mode) |*mini_mode| {
if (tui.mini_mode()) |mini_mode| {
mini_mode.text = self.file_path.items;
mini_mode.cursor = tui.egc_chunk_width(self.file_path.items, 0, 8);
}
@ -241,7 +241,7 @@ pub fn Create(options: type) type {
}
fn update_mini_mode_text(self: *Self) void {
if (tui.current().mini_mode) |*mini_mode| {
if (tui.mini_mode()) |mini_mode| {
mini_mode.text = self.file_path.items;
mini_mode.cursor = tui.egc_chunk_width(self.file_path.items, 0, 8);
}

View file

@ -140,7 +140,7 @@ fn load_history(self: *Self, pos: usize) void {
}
fn update_mini_mode_text(self: *Self) void {
if (tui.current().mini_mode) |*mini_mode| {
if (tui.mini_mode()) |mini_mode| {
mini_mode.text = self.input.items;
mini_mode.cursor = tui.egc_chunk_width(self.input.items, 0, 8);
}

View file

@ -81,7 +81,7 @@ fn start_query(self: *Self) !void {
}
fn update_mini_mode_text(self: *Self) void {
if (tui.current().mini_mode) |*mini_mode| {
if (tui.mini_mode()) |mini_mode| {
mini_mode.text = self.input;
mini_mode.cursor = tui.egc_chunk_width(self.input, 0, 8);
}

View file

@ -49,7 +49,7 @@ pub fn receive(self: *Self, _: tp.pid_ref, _: tp.message) error{Exit}!bool {
}
fn update_mini_mode_text(self: *Self) void {
if (tui.current().mini_mode) |*mini_mode| {
if (tui.mini_mode()) |mini_mode| {
mini_mode.text = if (self.input) |linenum|
(fmt.bufPrint(&self.buf, "{d}", .{linenum}) catch "")
else

View file

@ -4,7 +4,6 @@ const root = @import("root");
const command = @import("command");
const tui = @import("../../tui.zig");
const mainview = @import("../../mainview.zig");
pub const Type = @import("file_browser.zig").Create(@This());