diff --git a/src/config.zig b/src/config.zig index b58e87e..7a224c7 100644 --- a/src/config.zig +++ b/src/config.zig @@ -18,6 +18,6 @@ indent_size: usize = 4, tab_width: usize = 8, top_bar: []const u8 = "", -bottom_bar: []const u8 = "mode file log selection diagnostics linenumber", +bottom_bar: []const u8 = "mode file log selection diagnostics keybind linenumber", lsp_request_timeout: usize = 10, diff --git a/src/tui/status/keybindstate.zig b/src/tui/status/keybindstate.zig new file mode 100644 index 0000000..91b8310 --- /dev/null +++ b/src/tui/status/keybindstate.zig @@ -0,0 +1,43 @@ +const std = @import("std"); + +const EventHandler = @import("EventHandler"); +const Plane = @import("renderer").Plane; +const keybind = @import("keybind"); + +const Widget = @import("../Widget.zig"); + +allocator: std.mem.Allocator, +plane: Plane, + +const Self = @This(); + +pub fn create(allocator: std.mem.Allocator, parent: Plane, _: ?EventHandler) @import("widget.zig").CreateError!Widget { + const self: *Self = try allocator.create(Self); + self.* = .{ + .allocator = allocator, + .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent), + }; + return Widget.to(self); +} + +pub fn deinit(self: *Self, allocator: std.mem.Allocator) void { + self.plane.deinit(); + allocator.destroy(self); +} + +pub fn layout(_: *Self) Widget.Layout { + var buf: [256]u8 = undefined; + var fbs = std.io.fixedBufferStream(&buf); + const writer = fbs.writer(); + writer.print("{}", .{keybind.current_key_event_sequence_fmt()}) catch {}; + const len = fbs.getWritten().len; + return .{ .static = if (len > 0) len + 2 else 0 }; +} + +pub fn render(self: *Self, theme: *const Widget.Theme) bool { + self.plane.set_base_style(theme.statusbar); + self.plane.erase(); + self.plane.home(); + _ = self.plane.print(" {} ", .{keybind.current_key_event_sequence_fmt()}) catch {}; + return false; +} diff --git a/src/tui/status/widget.zig b/src/tui/status/widget.zig index 24ad530..fe52436 100644 --- a/src/tui/status/widget.zig +++ b/src/tui/status/widget.zig @@ -17,6 +17,7 @@ const widgets = std.static_string_map.StaticStringMap(CreateFunction).initCompti .{ "expander", @import("blank.zig").Create(.dynamic) }, .{ "spacer", @import("blank.zig").Create(.{ .static = 1 }) }, .{ "clock", @import("clock.zig").create }, + .{ "keybind", @import("keybindstate.zig").create }, }); pub const CreateError = error{ OutOfMemory, Exit }; pub const CreateFunction = *const fn (allocator: std.mem.Allocator, parent: Plane, event_handler: ?EventHandler) CreateError!Widget;