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
This commit is contained in:
Tim Culverhouse 2024-07-02 11:27:46 -05:00
parent 1a52178c1f
commit 2605613019
3 changed files with 7 additions and 1 deletions

View file

@ -6,6 +6,9 @@ style: Style = .{},
link: Hyperlink = .{}, link: Hyperlink = .{},
image: ?Image.Placement = null, image: ?Image.Placement = null,
default: bool = false, 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 /// Segment is a contiguous run of text that has a constant style
pub const Segment = struct { pub const Segment = struct {

View file

@ -366,6 +366,8 @@ pub fn render(self: *Vaxis, tty: AnyWriter) !void {
if (col >= self.screen.width) { if (col >= self.screen.width) {
row += 1; row += 1;
col = 0; col = 0;
// Rely on terminal wrapping to reposition into next row instead of forcing it
if (!cell.wrapped)
reposition = true; reposition = true;
} }
// If cell is the same as our last frame, we don't need to do // If cell is the same as our last frame, we don't need to do

View file

@ -309,6 +309,7 @@ pub fn print(self: Window, segments: []const Segment, opts: PrintOptions) !Print
}, },
.style = segment.style, .style = segment.style,
.link = segment.link, .link = segment.link,
.wrapped = col + w >= self.width,
}); });
col += w; col += w;
} }