From 2605613019a843accd49a2a7fe38d3b83f0cea1b Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Tue, 2 Jul 2024 11:27:46 -0500 Subject: [PATCH] vaxis: conditionally rely on terminal wrap to reposition cursor If the text was printed with a wrap, and we can determine this from the `print` method in Window, then we rely on the terminal for wrapping. This can help with primary screen text reflowing on resize --- src/Cell.zig | 3 +++ src/Vaxis.zig | 4 +++- src/Window.zig | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Cell.zig b/src/Cell.zig index 15d5484..e8a2197 100644 --- a/src/Cell.zig +++ b/src/Cell.zig @@ -6,6 +6,9 @@ style: Style = .{}, link: Hyperlink = .{}, image: ?Image.Placement = null, default: bool = false, +/// Set to true if this cell is the last cell printed in a row before wrap. Vaxis will determine if +/// it should rely on the terminal's autowrap feature which can help with primary screen resizes +wrapped: bool = false, /// Segment is a contiguous run of text that has a constant style pub const Segment = struct { diff --git a/src/Vaxis.zig b/src/Vaxis.zig index 18924a3..fc25ebe 100644 --- a/src/Vaxis.zig +++ b/src/Vaxis.zig @@ -366,7 +366,9 @@ pub fn render(self: *Vaxis, tty: AnyWriter) !void { if (col >= self.screen.width) { row += 1; col = 0; - reposition = true; + // Rely on terminal wrapping to reposition into next row instead of forcing it + if (!cell.wrapped) + reposition = true; } // If cell is the same as our last frame, we don't need to do // anything diff --git a/src/Window.zig b/src/Window.zig index 74b9eff..4181670 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -309,6 +309,7 @@ pub fn print(self: Window, segments: []const Segment, opts: PrintOptions) !Print }, .style = segment.style, .link = segment.link, + .wrapped = col + w >= self.width, }); col += w; }