aboutsummaryrefslogtreecommitdiff
path: root/src/renderer/mod.rs
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-07-03 17:00:00 -0700
committerJoe Wilm <joe@jwilm.com>2016-07-03 17:00:00 -0700
commit7f1c1efe474851a129e4a2e5bc012d9b76ed2ed0 (patch)
tree4fc278de8e08f16ff80d976c60c454a29e452e7f /src/renderer/mod.rs
parentbc2793a762b505d2d3c7af65e878f864a36cb19b (diff)
downloadalacritty-7f1c1efe474851a129e4a2e5bc012d9b76ed2ed0.tar.gz
alacritty-7f1c1efe474851a129e4a2e5bc012d9b76ed2ed0.zip
Grid API is now generic and strongly typed
The Grid no longer knows about a `Cell` and is instead generic. The `Cell` type is coupled to the `term` module already, and it's been moved there to reflect the strong relationship. Grid APIs previously accepted `usize` for many arguments. If the caller intended rows to be columns, but the function accepted them in reverse, there would be no compiler error. Now there is, and this should prevent such bugs from entering the code. The Grid internals grew significantly to accomodate the strongly typed APIs. There is now a `grid::index` module which defines Cursor, Line, and Column. The Grid APIs are all based on these types now. Indexing for Ranges proved to be somewhat awkward. A new range had to be constructed in the implementation. If the optimizer can't figure out what's going on in that case, the ranges may not be a zero-cost abstraction.
Diffstat (limited to 'src/renderer/mod.rs')
-rw-r--r--src/renderer/mod.rs27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs
index 19a69b8b..c967fa05 100644
--- a/src/renderer/mod.rs
+++ b/src/renderer/mod.rs
@@ -27,8 +27,8 @@ use gl;
use notify::{Watcher as WatcherApi, RecommendedWatcher as Watcher, op};
use font::{Rasterizer, RasterizedGlyph, FontDesc};
-use grid::{self, Grid, Cell, CellFlags};
-use term;
+use grid::{self, Grid};
+use term::{self, cell, Cell};
use super::Rgb;
@@ -80,8 +80,8 @@ pub struct Glyph {
/// Naïve glyph cache
///
-/// Currently only keyed by `char`, and thus not possible to hold different representations of the
-/// same code point.
+/// Currently only keyed by `char`, and thus not possible to hold different
+/// representations of the same code point.
pub struct GlyphCache {
/// Cache of buffered glyphs
cache: HashMap<char, Glyph>,
@@ -236,7 +236,7 @@ impl Batch {
bg_b: cell.bg.b as f32,
};
- if cell.flags.contains(grid::INVERSE) {
+ if cell.flags.contains(cell::INVERSE) {
instance.r = cell.bg.r as f32;
instance.g = cell.bg.g as f32;
instance.b = cell.bg.b as f32;
@@ -550,7 +550,7 @@ impl<'a> RenderApi<'a> {
c: c,
fg: *color,
bg: term::DEFAULT_BG,
- flags: grid::INVERSE,
+ flags: cell::INVERSE,
};
self.add_render_item(row, col, &cell, glyph);
}
@@ -576,22 +576,25 @@ impl<'a> RenderApi<'a> {
}
}
- pub fn render_cursor(&mut self, cursor: term::Cursor, glyph_cache: &mut GlyphCache) {
+ pub fn render_cursor(&mut self, cursor: &grid::index::Cursor, glyph_cache: &mut GlyphCache) {
if let Some(glyph) = glyph_cache.get(term::CURSOR_SHAPE, self) {
let cell = Cell {
c: term::CURSOR_SHAPE,
fg: term::DEFAULT_FG,
bg: term::DEFAULT_BG,
- flags: CellFlags::empty(),
+ flags: cell::Flags::empty(),
};
- self.add_render_item(cursor.y as f32, cursor.x as f32, &cell, glyph);
+ let y: usize = *cursor.line;
+ let x: usize = *cursor.col;
+
+ self.add_render_item(y as f32, x as f32, &cell, glyph);
}
}
- pub fn render_grid(&mut self, grid: &Grid, glyph_cache: &mut GlyphCache) {
- for (i, row) in grid.rows().enumerate() {
- for (j, cell) in row.cells().enumerate() {
+ pub fn render_grid(&mut self, grid: &Grid<Cell>, glyph_cache: &mut GlyphCache) {
+ for (i, line) in grid.lines().enumerate() {
+ for (j, cell) in line.cells().enumerate() {
// Skip empty cells
if cell.c == ' ' && cell.bg == term::DEFAULT_BG {
continue;