diff --git a/src/Grid.zig b/src/Grid.zig index 8daca2b1d..6cfd49993 100644 --- a/src/Grid.zig +++ b/src/Grid.zig @@ -16,7 +16,13 @@ const lru = @import("lru.zig"); const log = std.log.scoped(.grid); -const CellsLRU = lru.AutoHashMap(terminal.Screen.RowHeader.Id, std.ArrayListUnmanaged(GPUCell)); +// The LRU is keyed by (screen, row_id) since we need to cache rows +// separately for alt screens. By storing that in the key, we very likely +// have the cache already for when the primary screen is reactivated. +const CellsLRU = lru.AutoHashMap(struct { + screen: terminal.Terminal.ScreenType, + row_id: terminal.Screen.RowHeader.Id, +}, std.ArrayListUnmanaged(GPUCell)); alloc: std.mem.Allocator, @@ -379,7 +385,10 @@ pub fn rebuildCells(self: *Grid, term: *Terminal) !void { defer y += 1; // Get our value from the cache. - const gop = try self.cells_lru.getOrPut(self.alloc, row.getId()); + const gop = try self.cells_lru.getOrPut(self.alloc, .{ + .screen = term.active_screen, + .row_id = row.getId(), + }); if (!row.isDirty() and gop.found_existing) { var i: usize = self.cells.items.len; for (gop.value_ptr.items) |cell| { diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 1eae05331..9fb89a877 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -27,7 +27,7 @@ const log = std.log.scoped(.terminal); const TABSTOP_INTERVAL = 8; /// Screen type is an enum that tracks whether a screen is primary or alternate. -const ScreenType = enum { +pub const ScreenType = enum { primary, alternate, }; @@ -172,6 +172,8 @@ pub fn alternateScreen(self: *Terminal, options: AlternateScreenOptions) void { const tracy = trace(@src()); defer tracy.end(); + //log.info("alt screen active={} options={} cursor={}", .{ self.active_screen, options, self.screen.cursor }); + // TODO: test // TODO(mitchellh): what happens if we enter alternate screen multiple times? // for now, we ignore... @@ -199,6 +201,8 @@ pub fn primaryScreen(self: *Terminal, options: AlternateScreenOptions) void { const tracy = trace(@src()); defer tracy.end(); + //log.info("primary screen active={} options={}", .{ self.active_screen, options }); + // TODO: test // TODO(mitchellh): what happens if we enter alternate screen multiple times? if (self.active_screen == .primary) return; diff --git a/src/terminal/stream.zig b/src/terminal/stream.zig index e1904a70e..b7fe90994 100644 --- a/src/terminal/stream.zig +++ b/src/terminal/stream.zig @@ -51,7 +51,8 @@ pub fn Stream(comptime Handler: type) type { const actions = self.parser.next(c); for (actions) |action_opt| { // if (action_opt) |action| { - // log.info("action: {}", .{action}); + // if (action != .print) + // log.info("action: {}", .{action}); // } switch (action_opt orelse continue) { .print => |p| if (@hasDecl(T, "print")) try self.handler.print(p),