From 9e4d4a00e1695e1350204d777ab992f2ab266dc3 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Thu, 5 Feb 2026 23:01:19 +0100 Subject: [PATCH] fix: wrap info_view content at info_box_width_limit or screen width --- src/config.zig | 1 + src/tui/info_view.zig | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/config.zig b/src/config.zig index 21a9dba..e22f890 100644 --- a/src/config.zig +++ b/src/config.zig @@ -77,6 +77,7 @@ pane_right_style: WidgetStyle = .bar_left, pane_style: PaneStyle = .panel, hint_window_style: WidgetStyle = .thick_boxed, info_box_style: WidgetStyle = .bar_left_spacious, +info_box_width_limit: usize = 80, centered_view: bool = false, centered_view_width: usize = 145, diff --git a/src/tui/info_view.zig b/src/tui/info_view.zig index c3ee40b..1bc72dc 100644 --- a/src/tui/info_view.zig +++ b/src/tui/info_view.zig @@ -3,6 +3,8 @@ const Allocator = @import("std").mem.Allocator; const Plane = @import("renderer").Plane; const Widget = @import("Widget.zig"); const WidgetList = @import("WidgetList.zig"); +const reflow = @import("Buffer").reflow; +const tui = @import("tui.zig"); pub const name = @typeName(Self); @@ -13,6 +15,7 @@ plane: Plane, view_rows: usize = 0, lines: std.ArrayList([]const u8), +widget_type: Widget.Type, const default_widget_type: Widget.Type = .panel; @@ -28,6 +31,7 @@ pub fn create_widget_type(allocator: Allocator, parent: Plane, widget_type: Widg .allocator = allocator, .plane = try Plane.init(&(Widget.Box{}).opts(name), parent), .lines = .empty, + .widget_type = widget_type, }; container.ctx = self; try container.add(Widget.to(self)); @@ -56,7 +60,16 @@ pub fn handle_resize(self: *Self, pos: Widget.Box) void { pub fn append_content(self: *Self, content: []const u8) !void { var iter = std.mem.splitScalar(u8, content, '\n'); while (iter.next()) |line| if (line.len > 0) { - (try self.lines.addOne(self.allocator)).* = try self.allocator.dupe(u8, line); + const width = if (self.widget_type == .info_box) + tui.config().info_box_width_limit + else + tui.screen().w; + const text = try reflow(self.allocator, line, width); + defer self.allocator.free(text); + var iter_ = std.mem.splitScalar(u8, text, '\n'); + while (iter_.next()) |line_| if (line_.len > 0) { + (try self.lines.addOne(self.allocator)).* = try self.allocator.dupe(u8, line_); + }; }; }