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);
}