feat: add keybind status bar widget
This widget will show the state of the leader key sequence being processed.
This commit is contained in:
parent
a5849a7dab
commit
4e03fc99d4
3 changed files with 45 additions and 1 deletions
|
@ -18,6 +18,6 @@ indent_size: usize = 4,
|
||||||
tab_width: usize = 8,
|
tab_width: usize = 8,
|
||||||
|
|
||||||
top_bar: []const u8 = "",
|
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,
|
lsp_request_timeout: usize = 10,
|
||||||
|
|
43
src/tui/status/keybindstate.zig
Normal file
43
src/tui/status/keybindstate.zig
Normal file
|
@ -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;
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ const widgets = std.static_string_map.StaticStringMap(CreateFunction).initCompti
|
||||||
.{ "expander", @import("blank.zig").Create(.dynamic) },
|
.{ "expander", @import("blank.zig").Create(.dynamic) },
|
||||||
.{ "spacer", @import("blank.zig").Create(.{ .static = 1 }) },
|
.{ "spacer", @import("blank.zig").Create(.{ .static = 1 }) },
|
||||||
.{ "clock", @import("clock.zig").create },
|
.{ "clock", @import("clock.zig").create },
|
||||||
|
.{ "keybind", @import("keybindstate.zig").create },
|
||||||
});
|
});
|
||||||
pub const CreateError = error{ OutOfMemory, Exit };
|
pub const CreateError = error{ OutOfMemory, Exit };
|
||||||
pub const CreateFunction = *const fn (allocator: std.mem.Allocator, parent: Plane, event_handler: ?EventHandler) CreateError!Widget;
|
pub const CreateFunction = *const fn (allocator: std.mem.Allocator, parent: Plane, event_handler: ?EventHandler) CreateError!Widget;
|
||||||
|
|
Loading…
Add table
Reference in a new issue