refactor: move command and EventHandler out of the tui module
This commit is contained in:
		
							parent
							
								
									f41fb97d02
								
							
						
					
					
						commit
						16c5471126
					
				
					 45 changed files with 132 additions and 81 deletions
				
			
		| 
						 | 
				
			
			@ -1,4 +1,5 @@
 | 
			
		|||
const std = @import("std");
 | 
			
		||||
const EventHandler = @import("EventHandler");
 | 
			
		||||
 | 
			
		||||
const status_widget = @import("widget.zig");
 | 
			
		||||
const Widget = @import("../Widget.zig");
 | 
			
		||||
| 
						 | 
				
			
			@ -6,7 +7,7 @@ const WidgetList = @import("../WidgetList.zig");
 | 
			
		|||
 | 
			
		||||
pub const Style = enum { none, grip };
 | 
			
		||||
 | 
			
		||||
pub fn create(allocator: std.mem.Allocator, parent: Widget, config: []const u8, style: Style, event_handler: ?Widget.EventHandler) !Widget {
 | 
			
		||||
pub fn create(allocator: std.mem.Allocator, parent: Widget, config: []const u8, style: Style, event_handler: ?EventHandler) !Widget {
 | 
			
		||||
    var w = try WidgetList.createH(allocator, parent, "statusbar", .{ .static = 1 });
 | 
			
		||||
    if (style == .grip) w.after_render = render_grip;
 | 
			
		||||
    w.ctx = w;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,18 +1,19 @@
 | 
			
		|||
const std = @import("std");
 | 
			
		||||
const tp = @import("thespian");
 | 
			
		||||
const Plane = @import("renderer").Plane;
 | 
			
		||||
const EventHandler = @import("EventHandler");
 | 
			
		||||
 | 
			
		||||
const Widget = @import("../Widget.zig");
 | 
			
		||||
 | 
			
		||||
plane: Plane,
 | 
			
		||||
layout: Widget.Layout,
 | 
			
		||||
on_event: ?Widget.EventHandler,
 | 
			
		||||
on_event: ?EventHandler,
 | 
			
		||||
 | 
			
		||||
const Self = @This();
 | 
			
		||||
 | 
			
		||||
pub fn Create(comptime layout_: Widget.Layout) @import("widget.zig").CreateFunction {
 | 
			
		||||
    return struct {
 | 
			
		||||
        fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
 | 
			
		||||
        fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?EventHandler) @import("widget.zig").CreateError!Widget {
 | 
			
		||||
            const self: *Self = try allocator.create(Self);
 | 
			
		||||
            self.* = .{
 | 
			
		||||
                .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,6 +3,7 @@ const tp = @import("thespian");
 | 
			
		|||
const cbor = @import("cbor");
 | 
			
		||||
const zeit = @import("zeit");
 | 
			
		||||
 | 
			
		||||
const EventHandler = @import("EventHandler");
 | 
			
		||||
const Plane = @import("renderer").Plane;
 | 
			
		||||
 | 
			
		||||
const Widget = @import("../Widget.zig");
 | 
			
		||||
| 
						 | 
				
			
			@ -12,12 +13,12 @@ const tui = @import("../tui.zig");
 | 
			
		|||
allocator: std.mem.Allocator,
 | 
			
		||||
plane: Plane,
 | 
			
		||||
tick_timer: ?tp.Cancellable = null,
 | 
			
		||||
on_event: ?Widget.EventHandler,
 | 
			
		||||
on_event: ?EventHandler,
 | 
			
		||||
tz: zeit.timezone.TimeZone,
 | 
			
		||||
 | 
			
		||||
const Self = @This();
 | 
			
		||||
 | 
			
		||||
pub fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
 | 
			
		||||
pub fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?EventHandler) @import("widget.zig").CreateError!Widget {
 | 
			
		||||
    var env = std.process.getEnvMap(allocator) catch |e| return tp.exit_error(e, @errorReturnTrace());
 | 
			
		||||
    defer env.deinit();
 | 
			
		||||
    const self: *Self = try allocator.create(Self);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,10 +3,11 @@ const Allocator = std.mem.Allocator;
 | 
			
		|||
const tp = @import("thespian");
 | 
			
		||||
 | 
			
		||||
const Plane = @import("renderer").Plane;
 | 
			
		||||
const command = @import("command");
 | 
			
		||||
const EventHandler = @import("EventHandler");
 | 
			
		||||
 | 
			
		||||
const Widget = @import("../Widget.zig");
 | 
			
		||||
const Button = @import("../Button.zig");
 | 
			
		||||
const command = @import("../command.zig");
 | 
			
		||||
 | 
			
		||||
errors: usize = 0,
 | 
			
		||||
warnings: usize = 0,
 | 
			
		||||
| 
						 | 
				
			
			@ -17,7 +18,7 @@ rendered: [:0]const u8 = "",
 | 
			
		|||
 | 
			
		||||
const Self = @This();
 | 
			
		||||
 | 
			
		||||
pub fn create(allocator: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
 | 
			
		||||
pub fn create(allocator: Allocator, parent: Plane, event_handler: ?EventHandler) @import("widget.zig").CreateError!Widget {
 | 
			
		||||
    return Button.create_widget(Self, allocator, parent, .{
 | 
			
		||||
        .ctx = .{},
 | 
			
		||||
        .label = "",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,10 +7,11 @@ const root = @import("root");
 | 
			
		|||
 | 
			
		||||
const Plane = @import("renderer").Plane;
 | 
			
		||||
const style = @import("renderer").style;
 | 
			
		||||
const command = @import("command");
 | 
			
		||||
const EventHandler = @import("EventHandler");
 | 
			
		||||
 | 
			
		||||
const Widget = @import("../Widget.zig");
 | 
			
		||||
const Button = @import("../Button.zig");
 | 
			
		||||
const command = @import("../command.zig");
 | 
			
		||||
const tui = @import("../tui.zig");
 | 
			
		||||
 | 
			
		||||
allocator: Allocator,
 | 
			
		||||
| 
						 | 
				
			
			@ -35,7 +36,7 @@ eol_mode: Buffer.EolMode = .lf,
 | 
			
		|||
const project_icon = "";
 | 
			
		||||
const Self = @This();
 | 
			
		||||
 | 
			
		||||
pub fn create(allocator: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
 | 
			
		||||
pub fn create(allocator: Allocator, parent: Plane, event_handler: ?EventHandler) @import("widget.zig").CreateError!Widget {
 | 
			
		||||
    const btn = try Button.create(Self, allocator, parent, .{
 | 
			
		||||
        .ctx = .{
 | 
			
		||||
            .allocator = allocator,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,11 +7,11 @@ const Plane = @import("renderer").Plane;
 | 
			
		|||
const utils = @import("renderer").input.utils;
 | 
			
		||||
const key_ = @import("renderer").input.key;
 | 
			
		||||
const event_type = @import("renderer").input.event_type;
 | 
			
		||||
const command = @import("command");
 | 
			
		||||
const EventHandler = @import("EventHandler");
 | 
			
		||||
 | 
			
		||||
const Widget = @import("../Widget.zig");
 | 
			
		||||
const command = @import("../command.zig");
 | 
			
		||||
const tui = @import("../tui.zig");
 | 
			
		||||
const EventHandler = @import("../EventHandler.zig");
 | 
			
		||||
 | 
			
		||||
const history = 8;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -31,7 +31,7 @@ const Self = @This();
 | 
			
		|||
const idle_msg = "🐶";
 | 
			
		||||
pub const width = idle_msg.len + 20;
 | 
			
		||||
 | 
			
		||||
pub fn create(allocator: Allocator, parent: Plane, _: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
 | 
			
		||||
pub fn create(allocator: Allocator, parent: Plane, _: ?EventHandler) @import("widget.zig").CreateError!Widget {
 | 
			
		||||
    const frame_rate = tp.env.get().num("frame-rate");
 | 
			
		||||
    const self: *Self = try allocator.create(Self);
 | 
			
		||||
    self.* = .{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,10 +4,11 @@ const tp = @import("thespian");
 | 
			
		|||
const Buffer = @import("Buffer");
 | 
			
		||||
 | 
			
		||||
const Plane = @import("renderer").Plane;
 | 
			
		||||
const command = @import("command");
 | 
			
		||||
const EventHandler = @import("EventHandler");
 | 
			
		||||
 | 
			
		||||
const Widget = @import("../Widget.zig");
 | 
			
		||||
const Button = @import("../Button.zig");
 | 
			
		||||
const command = @import("../command.zig");
 | 
			
		||||
 | 
			
		||||
line: usize = 0,
 | 
			
		||||
lines: usize = 0,
 | 
			
		||||
| 
						 | 
				
			
			@ -18,7 +19,7 @@ eol_mode: Buffer.EolMode = .lf,
 | 
			
		|||
 | 
			
		||||
const Self = @This();
 | 
			
		||||
 | 
			
		||||
pub fn create(allocator: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
 | 
			
		||||
pub fn create(allocator: Allocator, parent: Plane, event_handler: ?EventHandler) @import("widget.zig").CreateError!Widget {
 | 
			
		||||
    return Button.create_widget(Self, allocator, parent, .{
 | 
			
		||||
        .ctx = .{},
 | 
			
		||||
        .label = "",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,7 @@ const std = @import("std");
 | 
			
		|||
const tp = @import("thespian");
 | 
			
		||||
const cbor = @import("cbor");
 | 
			
		||||
const log = @import("log");
 | 
			
		||||
 | 
			
		||||
const EventHandler = @import("EventHandler");
 | 
			
		||||
const Plane = @import("renderer").Plane;
 | 
			
		||||
 | 
			
		||||
const Widget = @import("../Widget.zig");
 | 
			
		||||
| 
						 | 
				
			
			@ -15,7 +15,7 @@ msg: std.ArrayList(u8),
 | 
			
		|||
msg_counter: usize = 0,
 | 
			
		||||
clear_timer: ?tp.Cancellable = null,
 | 
			
		||||
level: Level = .info,
 | 
			
		||||
on_event: ?Widget.EventHandler,
 | 
			
		||||
on_event: ?EventHandler,
 | 
			
		||||
 | 
			
		||||
const message_display_time_seconds = 2;
 | 
			
		||||
const error_display_time_seconds = 4;
 | 
			
		||||
| 
						 | 
				
			
			@ -26,7 +26,7 @@ const Level = enum {
 | 
			
		|||
    err,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
pub fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
 | 
			
		||||
pub fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?EventHandler) @import("widget.zig").CreateError!Widget {
 | 
			
		||||
    const self: *Self = try allocator.create(Self);
 | 
			
		||||
    self.* = .{
 | 
			
		||||
        .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,14 +3,15 @@ const Allocator = std.mem.Allocator;
 | 
			
		|||
 | 
			
		||||
const Plane = @import("renderer").Plane;
 | 
			
		||||
const style = @import("renderer").style;
 | 
			
		||||
const command = @import("command");
 | 
			
		||||
const EventHandler = @import("EventHandler");
 | 
			
		||||
 | 
			
		||||
const Widget = @import("../Widget.zig");
 | 
			
		||||
const Button = @import("../Button.zig");
 | 
			
		||||
const command = @import("../command.zig");
 | 
			
		||||
const tui = @import("../tui.zig");
 | 
			
		||||
const CreateError = @import("widget.zig").CreateError;
 | 
			
		||||
 | 
			
		||||
pub fn create(allocator: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!Widget {
 | 
			
		||||
pub fn create(allocator: Allocator, parent: Plane, event_handler: ?EventHandler) CreateError!Widget {
 | 
			
		||||
    return Button.create_widget(void, allocator, parent, .{
 | 
			
		||||
        .ctx = {},
 | 
			
		||||
        .label = tui.get_mode(),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,11 +7,11 @@ const Plane = @import("renderer").Plane;
 | 
			
		|||
const key = @import("renderer").input.key;
 | 
			
		||||
const event_type = @import("renderer").input.event_type;
 | 
			
		||||
const utils = @import("renderer").input.utils;
 | 
			
		||||
const command = @import("command");
 | 
			
		||||
const EventHandler = @import("EventHandler");
 | 
			
		||||
 | 
			
		||||
const Widget = @import("../Widget.zig");
 | 
			
		||||
const command = @import("../command.zig");
 | 
			
		||||
const tui = @import("../tui.zig");
 | 
			
		||||
const EventHandler = @import("../EventHandler.zig");
 | 
			
		||||
 | 
			
		||||
plane: Plane,
 | 
			
		||||
ctrl: bool = false,
 | 
			
		||||
| 
						 | 
				
			
			@ -23,7 +23,7 @@ const Self = @This();
 | 
			
		|||
 | 
			
		||||
pub const width = 5;
 | 
			
		||||
 | 
			
		||||
pub fn create(allocator: Allocator, parent: Plane, _: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
 | 
			
		||||
pub fn create(allocator: Allocator, parent: Plane, _: ?EventHandler) @import("widget.zig").CreateError!Widget {
 | 
			
		||||
    const self: *Self = try allocator.create(Self);
 | 
			
		||||
    self.* = .{
 | 
			
		||||
        .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,7 @@ const std = @import("std");
 | 
			
		|||
const Allocator = std.mem.Allocator;
 | 
			
		||||
const tp = @import("thespian");
 | 
			
		||||
const tracy = @import("tracy");
 | 
			
		||||
 | 
			
		||||
const EventHandler = @import("EventHandler");
 | 
			
		||||
const Plane = @import("renderer").Plane;
 | 
			
		||||
 | 
			
		||||
const Widget = @import("../Widget.zig");
 | 
			
		||||
| 
						 | 
				
			
			@ -14,11 +14,11 @@ cursels: usize = 0,
 | 
			
		|||
selection: ?ed.Selection = null,
 | 
			
		||||
buf: [256]u8 = undefined,
 | 
			
		||||
rendered: [:0]const u8 = "",
 | 
			
		||||
on_event: ?Widget.EventHandler,
 | 
			
		||||
on_event: ?EventHandler,
 | 
			
		||||
 | 
			
		||||
const Self = @This();
 | 
			
		||||
 | 
			
		||||
pub fn create(allocator: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget {
 | 
			
		||||
pub fn create(allocator: Allocator, parent: Plane, event_handler: ?EventHandler) @import("widget.zig").CreateError!Widget {
 | 
			
		||||
    const self: *Self = try allocator.create(Self);
 | 
			
		||||
    self.* = .{
 | 
			
		||||
        .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,9 @@
 | 
			
		|||
const std = @import("std");
 | 
			
		||||
const Widget = @import("../Widget.zig");
 | 
			
		||||
const EventHandler = @import("EventHandler");
 | 
			
		||||
const Plane = @import("renderer").Plane;
 | 
			
		||||
 | 
			
		||||
const Widget = @import("../Widget.zig");
 | 
			
		||||
 | 
			
		||||
const widgets = std.static_string_map.StaticStringMap(CreateFunction).initComptime(.{
 | 
			
		||||
    .{ "mode", @import("modestate.zig").create },
 | 
			
		||||
    .{ "file", @import("filestate.zig").create },
 | 
			
		||||
| 
						 | 
				
			
			@ -16,9 +18,9 @@ const widgets = std.static_string_map.StaticStringMap(CreateFunction).initCompti
 | 
			
		|||
    .{ "clock", @import("clock.zig").create },
 | 
			
		||||
});
 | 
			
		||||
pub const CreateError = error{ OutOfMemory, Exit };
 | 
			
		||||
pub const CreateFunction = *const fn (allocator: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!Widget;
 | 
			
		||||
pub const CreateFunction = *const fn (allocator: std.mem.Allocator, parent: Plane, event_handler: ?EventHandler) CreateError!Widget;
 | 
			
		||||
 | 
			
		||||
pub fn create(name: []const u8, allocator: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!?Widget {
 | 
			
		||||
pub fn create(name: []const u8, allocator: std.mem.Allocator, parent: Plane, event_handler: ?EventHandler) CreateError!?Widget {
 | 
			
		||||
    const create_ = widgets.get(name) orelse return null;
 | 
			
		||||
    return try create_(allocator, parent, event_handler);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue