From 2784f25b5bf71d4c63461750749aec5c058a525c Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Fri, 22 Sep 2023 17:43:32 -0500 Subject: [PATCH] terminal: reset cursor state before eraseDisplay in fullReset fullReset resets the state of the terminal. This method calls eraseDisplay, which depends on the state of the cursor pen for setting the cell styles when it erases. Reset the state of the cursor prior to calling eraseDisplay to ensure a clean reset. Fixes: alacritty/alt_reset test --- src/terminal/Terminal.zig | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index cdcda7fc5..f826f911a 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -1622,8 +1622,6 @@ pub fn kittyGraphics( pub fn fullReset(self: *Terminal, alloc: Allocator) void { self.primaryScreen(alloc, .{ .clear_on_exit = true, .cursor_save = true }); self.charset = .{}; - self.eraseDisplay(alloc, .scrollback); - self.eraseDisplay(alloc, .complete); self.modes = .{}; self.flags = .{}; self.tabstops.reset(0); @@ -1633,9 +1631,24 @@ pub fn fullReset(self: *Terminal, alloc: Allocator) void { self.screen.kitty_keyboard = .{}; self.scrolling_region = .{ .top = 0, .bottom = self.rows - 1 }; self.previous_char = null; + self.eraseDisplay(alloc, .scrollback); + self.eraseDisplay(alloc, .complete); self.pwd.clearRetainingCapacity(); } +test "Terminal: fullReset with a non-empty pen" { + var t = try init(testing.allocator, 80, 80); + defer t.deinit(testing.allocator); + + t.screen.cursor.pen.bg = .{ .r = 0xFF, .g = 0x00, .b = 0x7F }; + t.screen.cursor.pen.fg = .{ .r = 0xFF, .g = 0x00, .b = 0x7F }; + t.fullReset(testing.allocator); + + const cell = t.screen.getCell(.active, t.screen.cursor.y, t.screen.cursor.x); + try testing.expect(cell.bg.eql(.{})); + try testing.expect(cell.fg.eql(.{})); +} + test "Terminal: input with no control characters" { var t = try init(testing.allocator, 80, 80); defer t.deinit(testing.allocator);