From 087cdb93d971934cdf2a6a577d8d5fe94380611d Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 4 Dec 2021 21:04:30 -0500 Subject: delay allocation of the alternate screen --- src/grid.rs | 13 ++++++++++++- src/screen.rs | 5 ++++- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/grid.rs b/src/grid.rs index 246e9e6..9681638 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -21,7 +21,7 @@ impl Grid { size, pos: Pos::default(), saved_pos: Pos::default(), - rows: vec![crate::row::Row::new(size.cols); size.rows as usize], + rows: vec![], scroll_top: 0, scroll_bottom: size.rows - 1, origin_mode: false, @@ -32,6 +32,17 @@ impl Grid { } } + pub fn allocate_rows(&mut self) { + if self.rows.is_empty() { + self.rows.extend( + std::iter::repeat_with(|| { + crate::row::Row::new(self.size.cols) + }) + .take(self.size.rows as usize), + ); + } + } + fn new_row(&self) -> crate::row::Row { crate::row::Row::new(self.size.cols) } diff --git a/src/screen.rs b/src/screen.rs index 74e0559..ae6bd2d 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -85,8 +85,10 @@ impl Screen { size: crate::grid::Size, scrollback_len: usize, ) -> Self { + let mut grid = crate::grid::Grid::new(size, scrollback_len); + grid.allocate_rows(); Self { - grid: crate::grid::Grid::new(size, scrollback_len), + grid, alternate_grid: crate::grid::Grid::new(size, 0), attrs: crate::attrs::Attrs::default(), @@ -759,6 +761,7 @@ impl Screen { fn enter_alternate_grid(&mut self) { self.grid_mut().set_scrollback(0); self.set_mode(MODE_ALTERNATE_SCREEN); + self.alternate_grid.allocate_rows(); } fn exit_alternate_grid(&mut self) { -- cgit v1.2.3-54-g00ecf