From 1121002f68769a8946203e845807d2db87819d10 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 27 Feb 2024 21:59:48 -0800 Subject: [PATCH] terminal/new: fullreset --- src/terminal/Terminal.zig | 3 ++ src/terminal/new/Screen.zig | 3 ++ src/terminal/new/Terminal.zig | 66 +++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index d88207892..2d44bd0a0 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -2196,6 +2196,7 @@ pub fn fullReset(self: *Terminal, alloc: Allocator) void { self.status_display = .main; } +// X test "Terminal: fullReset with a non-empty pen" { var t = try init(testing.allocator, 80, 80); defer t.deinit(testing.allocator); @@ -2209,6 +2210,7 @@ test "Terminal: fullReset with a non-empty pen" { try testing.expect(cell.fg == .none); } +// X test "Terminal: fullReset origin mode" { var t = try init(testing.allocator, 10, 10); defer t.deinit(testing.allocator); @@ -2223,6 +2225,7 @@ test "Terminal: fullReset origin mode" { try testing.expect(!t.modes.get(.origin)); } +// X test "Terminal: fullReset status display" { var t = try init(testing.allocator, 10, 10); defer t.deinit(testing.allocator); diff --git a/src/terminal/new/Screen.zig b/src/terminal/new/Screen.zig index 02f3983a4..bd2b9d4d1 100644 --- a/src/terminal/new/Screen.zig +++ b/src/terminal/new/Screen.zig @@ -44,6 +44,9 @@ charset: CharsetState = .{}, /// protection mode since some sequences such as ECH depend on this. protected_mode: ansi.ProtectedMode = .off, +/// The kitty keyboard settings. +kitty_keyboard: kitty.KeyFlagStack = .{}, + /// Kitty graphics protocol state. kitty_images: kitty.graphics.ImageStorage = .{}, diff --git a/src/terminal/new/Terminal.zig b/src/terminal/new/Terminal.zig index 5aeabd7c1..306fd2762 100644 --- a/src/terminal/new/Terminal.zig +++ b/src/terminal/new/Terminal.zig @@ -2050,6 +2050,31 @@ pub fn plainString(self: *Terminal, alloc: Allocator) ![]const u8 { return try self.screen.dumpStringAlloc(alloc, .{ .viewport = .{} }); } +/// Full reset +pub fn fullReset(self: *Terminal) void { + self.primaryScreen(.{ .clear_on_exit = true, .cursor_save = true }); + self.screen.charset = .{}; + self.modes = .{}; + self.flags = .{}; + self.tabstops.reset(TABSTOP_INTERVAL); + self.screen.saved_cursor = null; + self.screen.selection = null; + self.screen.kitty_keyboard = .{}; + self.screen.protected_mode = .off; + self.scrolling_region = .{ + .top = 0, + .bottom = self.rows - 1, + .left = 0, + .right = self.cols - 1, + }; + self.previous_char = null; + self.eraseDisplay(.scrollback, false); + self.eraseDisplay(.complete, false); + self.screen.cursorAbsolute(0, 0); + self.pwd.clearRetainingCapacity(); + self.status_display = .main; +} + test "Terminal: input with no control characters" { const alloc = testing.allocator; var t = try init(alloc, 40, 40); @@ -7389,3 +7414,44 @@ test "Terminal: cursorIsAtPrompt alternate screen" { t.markSemanticPrompt(.prompt); try testing.expect(!t.cursorIsAtPrompt()); } + +test "Terminal: fullReset with a non-empty pen" { + var t = try init(testing.allocator, 80, 80); + defer t.deinit(testing.allocator); + + try t.setAttribute(.{ .direct_color_fg = .{ .r = 0xFF, .g = 0, .b = 0x7F } }); + try t.setAttribute(.{ .direct_color_bg = .{ .r = 0xFF, .g = 0, .b = 0x7F } }); + t.fullReset(); + + { + const list_cell = t.screen.pages.getCell(.{ .active = .{ + .x = t.screen.cursor.x, + .y = t.screen.cursor.y, + } }).?; + const cell = list_cell.cell; + try testing.expect(cell.style_id == 0); + } +} + +test "Terminal: fullReset origin mode" { + var t = try init(testing.allocator, 10, 10); + defer t.deinit(testing.allocator); + + t.setCursorPos(3, 5); + t.modes.set(.origin, true); + t.fullReset(); + + // Origin mode should be reset and the cursor should be moved + try testing.expectEqual(@as(usize, 0), t.screen.cursor.y); + try testing.expectEqual(@as(usize, 0), t.screen.cursor.x); + try testing.expect(!t.modes.get(.origin)); +} + +test "Terminal: fullReset status display" { + var t = try init(testing.allocator, 10, 10); + defer t.deinit(testing.allocator); + + t.status_display = .status_line; + t.fullReset(); + try testing.expect(t.status_display == .main); +}