From a35fc00f3142403e960e6c318f95c93f6c4c2e6d Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 14 Apr 2026 23:10:41 +0200 Subject: [PATCH] feat: improve rendering of tabs in filelist_view closes #530 --- src/tui/filelist_view.zig | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/tui/filelist_view.zig b/src/tui/filelist_view.zig index 8e2da8a7..435d4811 100644 --- a/src/tui/filelist_view.zig +++ b/src/tui/filelist_view.zig @@ -197,7 +197,34 @@ fn handle_render_menu(self: *Self, button: *ButtonType, theme: *const Widget.The .Warning => button.plane.set_style(style_warning), .Error => button.plane.set_style(style_error), } - _ = button.plane.print("{f}", .{std.ascii.hexEscape(entry.lines, .lower)}) catch {}; + const tab_width = tui.config().tab_width; + const show_tabs_visual = switch (tui.config().whitespace_mode) { + .tabs, .external, .visible, .full => true, + else => false, + }; + var codepoints = (std.unicode.Utf8View.init(entry.lines) catch std.unicode.Utf8View.initUnchecked(entry.lines)).iterator(); + while (codepoints.nextCodepointSlice()) |codepoint| { + const cp = std.unicode.utf8Decode(codepoint) catch { + for (codepoint) |b| _ = button.plane.print("\\x{x:0>2}", .{b}) catch {}; + continue; + }; + switch (cp) { + '\t' => { + const col: usize = @intCast(button.plane.cursor_x()); + const spaces = tab_width - (col % tab_width); + if (show_tabs_visual) { + button.plane.set_style(.{ .fg = theme.editor_whitespace.fg, .bg = style_label.bg }); + for (0..spaces) |i| + _ = button.plane.putstr(if (i < spaces - 1) editor.whitespace.char.tab_begin else editor.whitespace.char.tab_end) catch {}; + button.plane.set_style(style_label); + } else { + for (0..spaces) |_| _ = button.plane.putstr(" ") catch {}; + } + }, + 0x00...0x08, 0x0a...0x1f, 0x7f => _ = button.plane.print("\\x{x:0>2}", .{cp}) catch {}, + else => _ = button.plane.putstr(codepoint) catch {}, + } + } return false; }