From dfde2acf107ba406e9644d7c8c2841e3b82b2b5c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 22 Jul 2022 14:22:53 -0700 Subject: [PATCH] on resize, make sure we resize the alt screen too --- src/terminal/Screen.zig | 4 ++++ src/terminal/Terminal.zig | 5 +---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index 2a146bd1c..384f19aa0 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -346,6 +346,10 @@ pub fn resize(self: *Screen, alloc: Allocator, rows: usize, cols: usize) !void { self.rows = rows; self.cols = cols; + // Move our cursor if we have to so it stays on the screen. + self.cursor.x = @minimum(self.cursor.x, self.cols - 1); + self.cursor.y = @minimum(self.cursor.y, self.rows - 1); + // TODO: reflow due to soft wrap // If we're increasing height, then copy all rows (start at 0). diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 7d44ac912..71ee8f37f 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -156,6 +156,7 @@ pub fn resize(self: *Terminal, alloc: Allocator, cols: usize, rows: usize) !void // If we're making the screen smaller, dealloc the unused items. // TODO: reflow try self.screen.resize(alloc, rows, cols); + try self.secondary_screen.resize(alloc, rows, cols); // Set our size self.cols = cols; @@ -166,10 +167,6 @@ pub fn resize(self: *Terminal, alloc: Allocator, cols: usize, rows: usize) !void .top = 0, .bottom = rows - 1, }; - - // Move our cursor - self.screen.cursor.x = @minimum(self.screen.cursor.x, self.cols - 1); - self.screen.cursor.y = @minimum(self.screen.cursor.y, self.rows - 1); } /// Return the current string value of the terminal. Newlines are