aboutsummaryrefslogtreecommitdiff
path: root/src/grid
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2018-03-05 09:57:34 -0800
committerJoe Wilm <joe@jwilm.com>2018-03-07 09:51:06 -0800
commit2cfdd595f11377fbd91536a428e87d949ed9a05e (patch)
tree95ea005517dd55f7b16d474df765d15e234798ad /src/grid
parent69f533d19e282c8b2c808be081a562119052d081 (diff)
downloadalacritty-2cfdd595f11377fbd91536a428e87d949ed9a05e.tar.gz
alacritty-2cfdd595f11377fbd91536a428e87d949ed9a05e.zip
Move selection into Grid
Supporting selections with scrollback has two major components: 1. Grid needs access to Selection so that it may update the scroll position as the terminal text changes. 2. Selection needs to be implemented in terms of buffer offsets -- NOT lines -- and be updated when Storage is rotated. This commit implements the first part.
Diffstat (limited to 'src/grid')
-rw-r--r--src/grid/mod.rs22
-rw-r--r--src/grid/row.rs2
2 files changed, 18 insertions, 6 deletions
diff --git a/src/grid/mod.rs b/src/grid/mod.rs
index ca43471d..cf66a420 100644
--- a/src/grid/mod.rs
+++ b/src/grid/mod.rs
@@ -18,6 +18,7 @@ use std::cmp::{min, max, Ordering};
use std::ops::{Deref, Range, Index, IndexMut, RangeTo, RangeFrom, RangeFull};
use index::{self, Point, Line, Column, IndexRange, RangeInclusive};
+use selection::Selection;
mod row;
pub use self::row::Row;
@@ -54,8 +55,16 @@ impl<T> Deref for Indexed<T> {
}
}
+impl<T: PartialEq> ::std::cmp::PartialEq for Grid<T> {
+ fn eq(&self, other: &Self) -> bool {
+ self.cols.eq(&other.cols) &&
+ self.lines.eq(&other.lines) &&
+ self.raw.eq(&other.raw)
+ }
+}
+
/// Represents the terminal display contents
-#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
+#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Grid<T> {
/// Lines in the grid. Each row holds a list of cells corresponding to the
/// columns in that row.
@@ -73,14 +82,13 @@ pub struct Grid<T> {
///
/// This is used to quickly populate new lines and clear recycled lines
/// during scroll wrapping.
+ #[serde(skip)]
template_row: Row<T>,
/// Template cell for populating template_row
+ #[serde(skip)]
template: T,
- /// Temporary row storage for scrolling with a region
- temp: Vec<Row<T>>,
-
/// Offset of displayed area
///
/// If the displayed region isn't at the bottom of the screen, it stays
@@ -90,6 +98,10 @@ pub struct Grid<T> {
/// An limit on how far back it's possible to scroll
scroll_limit: usize,
+
+ /// Selected region
+ #[serde(skip)]
+ pub selection: Option<Selection>,
}
pub struct GridIterator<'a, T: 'a> {
@@ -117,9 +129,9 @@ impl<T: Copy + Clone> Grid<T> {
lines,
template_row,
template,
- temp: Vec::new(),
display_offset: 0,
scroll_limit: 0,
+ selection: None,
}
}
diff --git a/src/grid/row.rs b/src/grid/row.rs
index 6b6af7c8..f6b2a20e 100644
--- a/src/grid/row.rs
+++ b/src/grid/row.rs
@@ -21,7 +21,7 @@ use std::slice;
use index::Column;
/// A row in the grid
-#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
+#[derive(Default, Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct Row<T>(Vec<T>);
impl<T: Copy + Clone> Row<T> {