diff options
author | Joe Wilm <joe@jwilm.com> | 2016-12-26 22:52:37 -0500 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-12-26 22:56:19 -0500 |
commit | ae470bf68bf27921109890da3d90a5b61fa6a7aa (patch) | |
tree | d9e3d3a90f29471a0fe68a0e3966d95deb3a6f39 /src/term/cell.rs | |
parent | d28a7344731c4cd913687a893334555feed4e270 (diff) | |
download | alacritty-ae470bf68bf27921109890da3d90a5b61fa6a7aa.tar.gz alacritty-ae470bf68bf27921109890da3d90a5b61fa6a7aa.zip |
Implement copying selection for macOS
Still need automatic loading into selection copy buffer for linux.
Diffstat (limited to 'src/term/cell.rs')
-rw-r--r-- | src/term/cell.rs | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/src/term/cell.rs b/src/term/cell.rs index df648294..a95875bf 100644 --- a/src/term/cell.rs +++ b/src/term/cell.rs @@ -11,11 +11,11 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. - - use std::mem; use ansi::{NamedColor, Color}; +use grid; +use index::Column; bitflags! { #[derive(Serialize, Deserialize)] @@ -35,6 +35,27 @@ pub struct Cell { pub flags: Flags, } +/// Get the length of occupied cells in a line +pub trait LineLength { + /// Calculate the occupied line length + fn line_length(&self) -> Column; +} + +impl LineLength for grid::Row<Cell> { + fn line_length(&self) -> Column { + let mut length = Column(0); + + for (index, cell) in self[..].iter().rev().enumerate() { + if cell.c != ' ' { + length = Column(self.len() - index); + break; + } + } + + length + } +} + impl Cell { pub fn bold(&self) -> bool { self.flags.contains(BOLD) @@ -67,3 +88,21 @@ impl Cell { mem::swap(&mut self.fg, &mut self.bg); } } + +#[cfg(test)] +mod tests { + use super::{Cell, LineLength}; + + use grid::Row; + use index::Column; + use ansi::Color; + + #[test] + fn line_length_works() { + let template = Cell::new(' ', Color::Indexed(0), Color::Indexed(0)); + let mut row = Row::new(Column(10), &template); + row[Column(5)].c = 'a'; + + assert_eq!(row.line_length(), Column(6)); + } +} |