Compare commits

...

2 commits

3 changed files with 10 additions and 8 deletions

View file

@ -32,8 +32,9 @@ pub fn Options(context: type) type {
self.plane.fill(" ");
self.plane.home();
for (0..self.opts.padding) |_| _ = self.plane.putchar(" ");
if (self.opts.icon) |icon|
if (self.icon_width > 0) if (self.opts.icon) |icon| {
_ = self.plane.print("{s}", .{icon}) catch {};
};
if (self.text.items.len > 0) {
_ = self.plane.print("{s} ", .{self.text.items}) catch {};
} else {
@ -73,7 +74,7 @@ pub fn create(ctx_type: type, allocator: std.mem.Allocator, parent: Plane, opts:
.opts = opts,
.label = std.ArrayList(u8).init(allocator),
.text = std.ArrayList(u8).init(allocator),
.icon_width = @intCast(if (opts.icon) |icon| n.egc_chunk_width(icon, 0, 1) else 0),
.icon_width = @intCast(if (tui.config().show_fileicons) if (opts.icon) |icon| n.egc_chunk_width(icon, 0, 1) else 0 else 0),
};
try self.label.appendSlice(self.opts.label);
self.opts.label = self.label.items;

View file

@ -95,7 +95,7 @@ pub fn Variant(comptime command: []const u8, comptime label_: []const u8, allow_
if (!(cbor.matchString(&iter, &icon_) catch false)) @panic("invalid file_type icon");
if (!(cbor.matchInt(u24, &iter, &color) catch false)) @panic("invalid file_type color");
tui.render_file_icon(&button.plane, icon_, color);
const icon_width = tui.render_file_icon(&button.plane, icon_, color);
button.plane.set_style(style_label);
_ = button.plane.print("{s} ", .{description_}) catch {};
@ -110,7 +110,7 @@ pub fn Variant(comptime command: []const u8, comptime label_: []const u8, allow_
var len = cbor.decodeArrayHeader(&iter) catch return false;
while (len > 0) : (len -= 1) {
if (cbor.matchValue(&iter, cbor.extract(&index)) catch break) {
tui.render_match_cell(&button.plane, 0, index + 4, theme) catch break;
tui.render_match_cell(&button.plane, 0, index + 2 + icon_width, theme) catch break;
} else break;
}
return false;

View file

@ -1463,8 +1463,8 @@ pub fn get_buffer_state_indicator(buffer: *const @import("Buffer")) []const u8 {
return if (buffer.is_dirty()) dirty_indicator else if (buffer.is_hidden()) hidden_indicator else "";
}
pub fn render_file_icon(self: *renderer.Plane, icon: []const u8, color: u24) void {
if (!config().show_fileicons) return;
pub fn render_file_icon(self: *renderer.Plane, icon: []const u8, color: u24) usize {
if (!config().show_fileicons) return 0;
var cell = self.cell_init();
_ = self.at_cursor_cell(&cell) catch return;
if (!(color == 0xFFFFFF or color == 0x000000 or color == 0x000001)) {
@ -1474,6 +1474,7 @@ pub fn render_file_icon(self: *renderer.Plane, icon: []const u8, color: u24) voi
_ = self.putc(&cell) catch {};
self.cursor_move_rel(0, 1) catch {};
_ = self.print(" ", .{}) catch {};
return 3;
}
pub fn render_match_cell(self: *renderer.Plane, y: usize, x: usize, theme_: *const Widget.Theme) !void {
@ -1513,7 +1514,7 @@ pub fn render_file_item_cbor(self: *renderer.Plane, file_item_cbor: []const u8,
if (!(cbor.matchString(&iter, &icon) catch false)) @panic("invalid buffer file type icon");
if (!(cbor.matchInt(u24, &iter, &color) catch false)) @panic("invalid buffer file type color");
render_file_icon(self, icon, color);
const icon_width = render_file_icon(self, icon, color);
self.set_style(style_label);
_ = self.print("{s} ", .{file_path_}) catch {};
@ -1528,7 +1529,7 @@ pub fn render_file_item_cbor(self: *renderer.Plane, file_item_cbor: []const u8,
var len = cbor.decodeArrayHeader(&iter) catch return false;
while (len > 0) : (len -= 1) {
if (cbor.matchValue(&iter, cbor.extract(&index)) catch break) {
render_match_cell(self, 0, index + 5, theme_) catch break;
render_match_cell(self, 0, index + 2 + icon_width, theme_) catch break;
} else break;
}
return false;