refactor: split mini modes into input mode and a ui mode
This commit is contained in:
parent
d804203760
commit
f41fb97d02
6 changed files with 56 additions and 58 deletions
|
@ -34,7 +34,7 @@ pub fn Create(options: type) type {
|
|||
type: enum { dir, file, link },
|
||||
};
|
||||
|
||||
pub fn create(allocator: std.mem.Allocator, _: command.Context) !*Self {
|
||||
pub fn create(allocator: std.mem.Allocator, _: command.Context) !struct { tui.Mode, tui.MiniMode } {
|
||||
const self: *Self = try allocator.create(Self);
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
|
@ -47,7 +47,14 @@ pub fn Create(options: type) type {
|
|||
try options.load_entries(self);
|
||||
if (@hasDecl(options, "restore_state"))
|
||||
options.restore_state(self) catch {};
|
||||
return self;
|
||||
return .{
|
||||
.{
|
||||
.handler = EventHandler.to_owned(self),
|
||||
.name = options.name(self),
|
||||
.description = options.name(self),
|
||||
},
|
||||
.{},
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self) void {
|
||||
|
@ -60,14 +67,6 @@ pub fn Create(options: type) type {
|
|||
self.allocator.destroy(self);
|
||||
}
|
||||
|
||||
pub fn handler(self: *Self) EventHandler {
|
||||
return EventHandler.to_owned(self);
|
||||
}
|
||||
|
||||
pub fn name(self: *Self) []const u8 {
|
||||
return options.name(self);
|
||||
}
|
||||
|
||||
pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
||||
var evtype: u32 = undefined;
|
||||
var keypress: u32 = undefined;
|
||||
|
|
|
@ -16,6 +16,7 @@ const eql = @import("std").mem.eql;
|
|||
const ArrayList = @import("std").ArrayList;
|
||||
|
||||
const Self = @This();
|
||||
const name = " find";
|
||||
|
||||
allocator: Allocator,
|
||||
input: ArrayList(u8),
|
||||
|
@ -25,7 +26,7 @@ start_cursor: ed.Cursor,
|
|||
editor: *ed.Editor,
|
||||
history_pos: ?usize = null,
|
||||
|
||||
pub fn create(allocator: Allocator, _: command.Context) !*Self {
|
||||
pub fn create(allocator: Allocator, _: command.Context) !struct { tui.Mode, tui.MiniMode } {
|
||||
if (tui.current().mainview.dynamic_cast(mainview)) |mv_| if (mv_.get_editor()) |editor| {
|
||||
const self: *Self = try allocator.create(Self);
|
||||
self.* = .{
|
||||
|
@ -41,7 +42,14 @@ pub fn create(allocator: Allocator, _: command.Context) !*Self {
|
|||
defer self.allocator.free(text);
|
||||
try self.input.appendSlice(text);
|
||||
}
|
||||
return self;
|
||||
return .{
|
||||
.{
|
||||
.handler = EventHandler.to_owned(self),
|
||||
.name = name,
|
||||
.description = name,
|
||||
},
|
||||
.{},
|
||||
};
|
||||
};
|
||||
return error.NotFound;
|
||||
}
|
||||
|
@ -52,14 +60,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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -13,20 +13,28 @@ const Allocator = @import("std").mem.Allocator;
|
|||
const fmt = @import("std").fmt;
|
||||
|
||||
const Self = @This();
|
||||
const name = "#goto";
|
||||
|
||||
allocator: Allocator,
|
||||
buf: [30]u8 = undefined,
|
||||
input: ?usize = null,
|
||||
start: usize,
|
||||
|
||||
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_| if (mv_.get_editor()) |editor| {
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
.start = editor.get_primary().cursor.row + 1,
|
||||
};
|
||||
return self;
|
||||
return .{
|
||||
.{
|
||||
.handler = EventHandler.to_owned(self),
|
||||
.name = name,
|
||||
.description = name,
|
||||
},
|
||||
.{},
|
||||
};
|
||||
};
|
||||
return error.NotFound;
|
||||
}
|
||||
|
@ -35,14 +43,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 "#goto";
|
||||
}
|
||||
|
||||
pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
||||
var evtype: u32 = undefined;
|
||||
var keypress: u32 = undefined;
|
||||
|
|
|
@ -29,7 +29,7 @@ const Operation = enum {
|
|||
select,
|
||||
};
|
||||
|
||||
pub fn create(allocator: Allocator, ctx: command.Context) !*Self {
|
||||
pub fn create(allocator: Allocator, ctx: command.Context) !struct { tui.Mode, tui.MiniMode } {
|
||||
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;
|
||||
|
@ -39,18 +39,21 @@ pub fn create(allocator: Allocator, ctx: command.Context) !*Self {
|
|||
.direction = if (right) .right else .left,
|
||||
.operation = if (select) .select else .move,
|
||||
};
|
||||
return self;
|
||||
return .{
|
||||
.{
|
||||
.handler = EventHandler.to_owned(self),
|
||||
.name = self.name(),
|
||||
.description = self.name(),
|
||||
},
|
||||
.{},
|
||||
};
|
||||
}
|
||||
|
||||
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: *Self) []const u8 {
|
||||
fn name(self: *Self) []const u8 {
|
||||
return switch (self.operation) {
|
||||
.move => switch (self.direction) {
|
||||
.left => "↶ move",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue