From bb94364ce00a59044322d3d403d08e83d841d9d4 Mon Sep 17 00:00:00 2001 From: Amp Date: Wed, 21 Oct 2026 12:44:46 +0000 Subject: [PATCH] vaxis: hide the cursor when resizing resize() replaces both screens with fresh ones whose cursor_vis is false, but never hides the terminal cursor. The terminal therefore shows a cursor that vaxis believes is hidden. If the next frame is empty and the application hides the cursor, render() sees no change and writes nothing, leaving the cursor visible at the home position. Send hide_cursor along with the reset and erase sequences so the terminal matches the new screen state. Applications that show the cursor are unaffected, since their next render() detects the change and shows it again. Fixes: #373 Co-authored-by: Tim Culverhouse --- src/Vaxis.zig | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Vaxis.zig b/src/Vaxis.zig index 038847a..f7a88b5 100644 --- a/src/Vaxis.zig +++ b/src/Vaxis.zig @@ -197,8 +197,8 @@ pub fn resetState(self: *Vaxis, tty: *std.Io.Writer) !void { /// resize allocates a slice of cells equal to the number of cells /// required to display the screen (ie width x height). Any previous screen is -/// freed when resizing. The cursor will be sent to it's home position and a -/// hardware clear-below-cursor will be sent +/// freed when resizing. The cursor will be sent to it's home position, a +/// hardware clear-below-cursor will be sent, and the cursor will be hidden pub fn resize( self: *Vaxis, alloc: std.mem.Allocator, @@ -232,7 +232,7 @@ pub fn resize( } self.state.cursor.row = 0; self.state.cursor.col = 0; - try tty.writeAll(ctlseqs.sgr_reset ++ ctlseqs.erase_below_cursor); + try tty.writeAll(ctlseqs.sgr_reset ++ ctlseqs.erase_below_cursor ++ ctlseqs.hide_cursor); try tty.flush(); } @@ -1702,6 +1702,27 @@ test "render: no output when no changes" { try std.testing.expectEqual(@as(usize, 0), output.len); } +test "resize: hides the cursor when the frame is left empty" { + var env_map = try std.testing.environ.createMap(std.testing.allocator); + defer env_map.deinit(); + var vx = try Vaxis.init(std.testing.io, std.testing.allocator, &env_map, .{}); + var writer: std.Io.Writer.Allocating = .init(std.testing.allocator); + defer writer.deinit(); + defer vx.deinit(std.testing.allocator, &writer.writer); + + try vx.enterAltScreen(&writer.writer); + try vx.resize(std.testing.allocator, &writer.writer, .{ .rows = 3, .cols = 3, .x_pixel = 0, .y_pixel = 0 }); + const win = vx.window(); + win.clear(); + win.hideCursor(); + try vx.render(&writer.writer); + + const output = writer.written(); + const hide = std.mem.lastIndexOf(u8, output, ctlseqs.hide_cursor) orelse return error.TestUnexpectedResult; + if (std.mem.lastIndexOf(u8, output, ctlseqs.show_cursor)) |show| + try std.testing.expect(show < hide); +} + fn testResizeAllocationFailures(allocator: std.mem.Allocator) !void { var env_map = try std.testing.environ.createMap(allocator); defer env_map.deinit(); -- knotmirror 0.0.1