aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2018-04-07 01:50:14 +0200
committerJoe Wilm <jwilm@users.noreply.github.com>2018-04-24 09:59:52 -0700
commite99e40059dd6527568279f885d682dcf0568d620 (patch)
tree62e9ebf8ab58ce779256e6fc0d48ace48271609f
parent0d568180761d7da56e756762d5f4b1555eea6a7f (diff)
downloadalacritty-e99e40059dd6527568279f885d682dcf0568d620.tar.gz
alacritty-e99e40059dd6527568279f885d682dcf0568d620.zip
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.
-rw-r--r--src/grid/mod.rs17
-rw-r--r--src/grid/storage.rs11
2 files changed, 22 insertions, 6 deletions
diff --git a/src/grid/mod.rs b/src/grid/mod.rs
index 15ddf30e..e42e5cfa 100644
--- a/src/grid/mod.rs
+++ b/src/grid/mod.rs
@@ -211,7 +211,10 @@ impl<T: Copy + Clone> Grid<T> {
}
fn increase_scroll_limit(&mut self, count: usize) {
- self.scroll_limit = min(self.scroll_limit + count, self.raw.len() - *self.lines);
+ self.scroll_limit = min(
+ self.scroll_limit + count,
+ self.raw.len().saturating_sub(*self.lines),
+ );
}
fn decrease_scroll_limit(&mut self, count: usize) {
@@ -240,6 +243,13 @@ impl<T: Copy + Clone> Grid<T> {
self.raw.set_visible_lines(new_line_count);
self.lines = new_line_count;
+ // Fill up the history with empty lines
+ if self.raw.len() < self.raw.capacity() {
+ for _ in self.raw.len()..self.raw.capacity() {
+ self.raw.push(Row::new(self.cols, &template));
+ }
+ }
+
// Add new lines to bottom
self.scroll_up(&(Line(0)..new_line_count), lines_added, template);
@@ -263,11 +273,6 @@ impl<T: Copy + Clone> Grid<T> {
///
/// Alacritty takes the same approach.
fn shrink_lines(&mut self, target: index::Line) {
- // TODO handle disabled scrollback
- // while index::Line(self.raw.len()) != lines {
- // self.raw.pop();
- // }
-
let prev = self.lines;
self.selection = None;
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<T> Storage<T> {
}
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;
}