aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAyose <ayosec@gmail.com>2022-07-15 20:35:53 +0100
committerAyose <ayosec@gmail.com>2022-07-15 20:35:53 +0100
commit8d2016bbef1adb2e469b1c3bb650ed891b099b98 (patch)
treeda835bc108f890fa93f3581b7b1077c6744323ce
parentbf743df94214c90708d008debbc66ea36c771c47 (diff)
downloadr-alacritty-8d2016bbef1adb2e469b1c3bb650ed891b099b98.tar.gz
r-alacritty-8d2016bbef1adb2e469b1c3bb650ed891b099b98.tar.bz2
r-alacritty-8d2016bbef1adb2e469b1c3bb650ed891b099b98.zip
Initialize cell dimensions when create a Graphics instance.
This fixes a bug that crashes the terminal when a graphic is added before resizing the window.
-rw-r--r--alacritty_terminal/src/graphics/mod.rs10
-rw-r--r--alacritty_terminal/src/term/mod.rs4
2 files changed, 11 insertions, 3 deletions
diff --git a/alacritty_terminal/src/graphics/mod.rs b/alacritty_terminal/src/graphics/mod.rs
index b6f58a11..4641a912 100644
--- a/alacritty_terminal/src/graphics/mod.rs
+++ b/alacritty_terminal/src/graphics/mod.rs
@@ -296,6 +296,14 @@ pub struct Graphics {
}
impl Graphics {
+ /// Create a new instance, and initialize it with the dimensions of the
+ /// window.
+ pub fn new<S: Dimensions>(size: &S) -> Self {
+ let mut graphics = Graphics::default();
+ graphics.resize(size);
+ graphics
+ }
+
/// Generate a new graphic identifier.
pub fn next_id(&mut self) -> GraphicId {
self.last_id += 1;
@@ -333,7 +341,7 @@ impl Graphics {
}
/// Update cell dimensions.
- pub fn resize<S: Dimensions>(&mut self, size: S) {
+ pub fn resize<S: Dimensions>(&mut self, size: &S) {
self.cell_height = size.cell_height();
self.cell_width = size.cell_width();
}
diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs
index 4fc4032b..b02e40f4 100644
--- a/alacritty_terminal/src/term/mod.rs
+++ b/alacritty_terminal/src/term/mod.rs
@@ -373,7 +373,7 @@ impl<T> Term<T> {
title: None,
title_stack: Vec::new(),
selection: None,
- graphics: Graphics::default(),
+ graphics: Graphics::new(dimensions),
damage,
}
}
@@ -665,7 +665,7 @@ impl<T> Term<T> {
self.damage.resize(num_cols, num_lines);
// Update size information for graphics.
- self.graphics.resize(size);
+ self.graphics.resize(&size);
}
/// Active terminal modes.