refactor: split mini modes into input mode and a ui mode

This commit is contained in:
CJ van den Berg 2024-10-25 18:40:01 +02:00
parent d804203760
commit f41fb97d02
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
6 changed files with 56 additions and 58 deletions

View file

@ -14,6 +14,7 @@ const Allocator = @import("std").mem.Allocator;
const eql = @import("std").mem.eql;
const Self = @This();
const name = "󰥨 find";
allocator: Allocator,
buf: [1024]u8 = undefined,
@ -22,7 +23,7 @@ last_buf: [1024]u8 = undefined,
last_input: []u8 = "",
mainview: *mainview,
pub fn create(allocator: Allocator, _: command.Context) !*Self {
pub fn create(allocator: Allocator, _: command.Context) !struct { tui.Mode, tui.MiniMode } {
const self: *Self = try allocator.create(Self);
if (tui.current().mainview.dynamic_cast(mainview)) |mv| {
self.* = .{
@ -35,7 +36,14 @@ pub fn create(allocator: Allocator, _: command.Context) !*Self {
@memcpy(self.buf[0..text.len], text);
self.input = self.buf[0..text.len];
};
return self;
return .{
.{
.handler = EventHandler.to_owned(self),
.name = name,
.description = name,
},
.{},
};
}
return error.NotFound;
}
@ -44,14 +52,6 @@ pub fn deinit(self: *Self) void {
self.allocator.destroy(self);
}
pub fn handler(self: *Self) EventHandler {
return EventHandler.to_owned(self);
}
pub fn name(_: *Self) []const u8 {
return "󰥨 find";
}
pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
var evtype: u32 = undefined;
var keypress: u32 = undefined;