Skip to content

Commit f0eaa3c

Browse files
committed
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: #63
1 parent 81a6b37 commit f0eaa3c

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/Vaxis.zig

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,11 @@ pub fn resize(
180180
if (self.state.alt_screen)
181181
try tty.writeAll(ctlseqs.home)
182182
else {
183+
try tty.writeBytesNTimes(ctlseqs.ri, self.state.cursor.row);
183184
try tty.writeByte('\r');
184-
var i: usize = 0;
185-
while (i < self.state.cursor.row) : (i += 1) {
186-
try tty.writeAll(ctlseqs.ri);
187-
}
188185
}
186+
self.state.cursor.row = 0;
187+
self.state.cursor.col = 0;
189188
try tty.writeAll(ctlseqs.sgr_reset ++ ctlseqs.erase_below_cursor);
190189
}
191190

@@ -401,9 +400,9 @@ pub fn render(self: *Vaxis, tty: AnyWriter) !void {
401400
if (n > 0)
402401
try tty.print(ctlseqs.cuf, .{n});
403402
} else {
404-
try tty.writeByte('\r');
405403
const n = row - cursor_pos.row;
406404
try tty.writeByteNTimes('\n', n);
405+
try tty.writeByte('\r');
407406
if (col > 0)
408407
try tty.print(ctlseqs.cuf, .{col});
409408
}

0 commit comments

Comments
 (0)