From 8ef062efd94975885776e61b6df936088b018da0 Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Mon, 5 Mar 2018 09:57:34 -0800 Subject: 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. --- src/grid/mod.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/grid/mod.rs') 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 Deref for Indexed { } } +impl ::std::cmp::PartialEq for Grid { + 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 { /// 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 { /// /// This is used to quickly populate new lines and clear recycled lines /// during scroll wrapping. + #[serde(skip)] template_row: Row, /// Template cell for populating template_row + #[serde(skip)] template: T, - /// Temporary row storage for scrolling with a region - temp: Vec>, - /// 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 { /// An limit on how far back it's possible to scroll scroll_limit: usize, + + /// Selected region + #[serde(skip)] + pub selection: Option, } pub struct GridIterator<'a, T: 'a> { @@ -117,9 +129,9 @@ impl Grid { lines, template_row, template, - temp: Vec::new(), display_offset: 0, scroll_limit: 0, + selection: None, } } -- cgit