From f0eaa3c831f6376e7fa0519c275cdcb764580e12 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Sun, 21 Jul 2024 21:13:24 -0500 Subject: [PATCH] resize: properly handle state reset on primary screen When drawing on the primary screen The internal state of the cursor location was not being updated. This resulted in an invalid state and a messed up screen Fixes: https://github.com/rockorager/libvaxis/issues/63 --- src/Vaxis.zig | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Vaxis.zig b/src/Vaxis.zig index 878bb61..f71eaa7 100644 --- a/src/Vaxis.zig +++ b/src/Vaxis.zig @@ -180,12 +180,11 @@ pub fn resize( if (self.state.alt_screen) try tty.writeAll(ctlseqs.home) else { + try tty.writeBytesNTimes(ctlseqs.ri, self.state.cursor.row); try tty.writeByte('\r'); - var i: usize = 0; - while (i < self.state.cursor.row) : (i += 1) { - try tty.writeAll(ctlseqs.ri); - } } + self.state.cursor.row = 0; + self.state.cursor.col = 0; try tty.writeAll(ctlseqs.sgr_reset ++ ctlseqs.erase_below_cursor); } @@ -401,9 +400,9 @@ pub fn render(self: *Vaxis, tty: AnyWriter) !void { if (n > 0) try tty.print(ctlseqs.cuf, .{n}); } else { - try tty.writeByte('\r'); const n = row - cursor_pos.row; try tty.writeByteNTimes('\n', n); + try tty.writeByte('\r'); if (col > 0) try tty.print(ctlseqs.cuf, .{col}); }