diff options
author | Christian Duerr <contact@christianduerr.com> | 2021-03-30 23:25:38 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-30 23:25:38 +0000 |
commit | 3bd5ac221ab3b122962063edd1f4c10f9f2d117f (patch) | |
tree | b0a367b91611e911344aec9ff35354e5a473b6aa /alacritty/src/renderer | |
parent | 974392cdc6fdf1ba0d213145ae578a9316e9d404 (diff) | |
download | r-alacritty-3bd5ac221ab3b122962063edd1f4c10f9f2d117f.tar.gz r-alacritty-3bd5ac221ab3b122962063edd1f4c10f9f2d117f.tar.bz2 r-alacritty-3bd5ac221ab3b122962063edd1f4c10f9f2d117f.zip |
Unify the grid line indexing types
Previously Alacritty was using two different ways to reference lines in
the terminal. Either a `usize`, or a `Line(usize)`. These indexing
systems both served different purposes, but made it difficult to reason
about logic involving these systems because of its inconsistency.
To resolve this issue, a single new `Line(i32)` type has been
introduced. All existing references to lines and points now rely on
this definition of a line.
The indexing starts at the top of the terminal region with the line 0,
which matches the line 1 used by escape sequences. Each line in the
history becomes increasingly negative and the bottommost line is equal
to the number of visible lines minus one.
Having a system which goes into the negatives allows following the
escape sequence's indexing system closely, while at the same time making
it trivial to implement `Ord` for points.
The Alacritty UI crate is the only place which has a different indexing
system, since rendering and input puts the zero line at the top of the
viewport, rather than the top of the terminal region.
All instances which refer to a number of lines/columns instead of just a
single Line/Column have also been changed to use a `usize` instead. This
way a Line/Column will always refer to a specific place in the grid and
no confusion is created by having a count of lines as a possible index
into the grid storage.
Diffstat (limited to 'alacritty/src/renderer')
-rw-r--r-- | alacritty/src/renderer/mod.rs | 5 | ||||
-rw-r--r-- | alacritty/src/renderer/rects.rs | 17 |
2 files changed, 11 insertions, 11 deletions
diff --git a/alacritty/src/renderer/mod.rs b/alacritty/src/renderer/mod.rs index 4d752463..414d9bd5 100644 --- a/alacritty/src/renderer/mod.rs +++ b/alacritty/src/renderer/mod.rs @@ -481,7 +481,7 @@ impl Batch { self.instances.push(InstanceData { col: cell.point.column.0 as u16, - row: cell.point.line.0 as u16, + row: cell.point.line as u16, top: glyph.top, left: glyph.left, @@ -830,7 +830,7 @@ impl<'a> RenderApi<'a> { pub fn render_string( &mut self, glyph_cache: &mut GlyphCache, - point: Point, + point: Point<usize>, fg: Rgb, bg: Rgb, string: &str, @@ -846,7 +846,6 @@ impl<'a> RenderApi<'a> { bg_alpha: 1.0, fg, bg, - is_match: false, }) .collect::<Vec<_>>(); diff --git a/alacritty/src/renderer/rects.rs b/alacritty/src/renderer/rects.rs index fd966d27..591c9f46 100644 --- a/alacritty/src/renderer/rects.rs +++ b/alacritty/src/renderer/rects.rs @@ -3,6 +3,7 @@ use std::mem; use crossfont::Metrics; +use alacritty_terminal::grid::Dimensions; use alacritty_terminal::index::{Column, Point}; use alacritty_terminal::term::cell::Flags; use alacritty_terminal::term::color::Rgb; @@ -31,8 +32,8 @@ impl RenderRect { #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct RenderLine { - pub start: Point, - pub end: Point, + pub start: Point<usize>, + pub end: Point<usize>, pub color: Rgb, } @@ -42,7 +43,7 @@ impl RenderLine { let mut start = self.start; while start.line < self.end.line { - let end = Point::new(start.line, size.cols() - 1); + let end = Point::new(start.line, size.last_column()); Self::push_rects(&mut rects, metrics, size, flag, start, end, self.color); start = Point::new(start.line + 1, Column(0)); } @@ -57,8 +58,8 @@ impl RenderLine { metrics: &Metrics, size: &SizeInfo, flag: Flags, - start: Point, - end: Point, + start: Point<usize>, + end: Point<usize>, color: Rgb, ) { let (position, thickness) = match flag { @@ -99,8 +100,8 @@ impl RenderLine { fn create_rect( size: &SizeInfo, descent: f32, - start: Point, - end: Point, + start: Point<usize>, + end: Point<usize>, position: f32, mut thickness: f32, color: Rgb, @@ -112,7 +113,7 @@ impl RenderLine { // Make sure lines are always visible. thickness = thickness.max(1.); - let line_bottom = (start.line.0 as f32 + 1.) * size.cell_height(); + let line_bottom = (start.line as f32 + 1.) * size.cell_height(); let baseline = line_bottom + descent; let mut y = (baseline - position - thickness / 2.).ceil(); |