From e615d112fb9fffe46121bd9068498b07c4733fa8 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sat, 7 Apr 2018 01:50:14 +0200 Subject: Fix scrollback history size 0 bug There was an issue where alacritty would panic whenever the scrollback history size is set to 0, this fixes that issue. The panic was caused by a substraction with unsigned integers which was underflowing, this has been fixed to use `saturating_sub`. After that was fixed there was still a bug where scrollback would not behave correctly because the number of lines in the grid was decided at startup. This has been adapted so whenever the size of the terminal changes, the scrollback history and grid adapts to make sure the number of lines in the terminal is always the number of visible lines plus the amount of scrollback lines configured in the config file. This fixes #1150. --- src/grid/storage.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/grid/storage.rs') diff --git a/src/grid/storage.rs b/src/grid/storage.rs index b620b9c0..cc32d6d1 100644 --- a/src/grid/storage.rs +++ b/src/grid/storage.rs @@ -48,6 +48,17 @@ impl Storage { } pub fn set_visible_lines(&mut self, next: Line) { + // Change capacity to fit scrollback + screen size + if next > self.visible_lines + 1 { + self.inner.reserve_exact((next - (self.visible_lines + 1)).0); + } else if next < self.visible_lines + 1 { + let shrinkage = (self.visible_lines + 1 - next).0; + let new_size = self.inner.capacity() - shrinkage; + self.inner.truncate(new_size); + self.inner.shrink_to_fit(); + } + + // Update visible lines self.visible_lines = next - 1; } -- cgit