summaryrefslogtreecommitdiff
path: root/src/grid.rs
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-06-04 19:40:30 -0700
committerJoe Wilm <joe@jwilm.com>2016-06-04 19:40:30 -0700
commit4fdd5280f1e79ea6575a6a110951c564a7dd235e (patch)
tree89d11f7b903c53e974dca13d9dff227269cd57c1 /src/grid.rs
parent2f058bd053f52307bdbf3709209418ac26871678 (diff)
downloadalacritty-4fdd5280f1e79ea6575a6a110951c564a7dd235e.tar.gz
alacritty-4fdd5280f1e79ea6575a6a110951c564a7dd235e.zip
Add iterator methods to Grid and Row types
The iterator methods simplify logic in the main grid render function. To disambiguate iterator methods from those returning counts (and to free up names), the `rows()` and `cols()` methods on `Grid` have been renamed to `num_rows()` and `num_cols()`, respectively.
Diffstat (limited to 'src/grid.rs')
-rw-r--r--src/grid.rs24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/grid.rs b/src/grid.rs
index 765a5e1a..a3009f8b 100644
--- a/src/grid.rs
+++ b/src/grid.rs
@@ -1,8 +1,8 @@
//! Functions for computing properties of the terminal grid
-use std::collections::VecDeque;
-
+use std::collections::{vec_deque, VecDeque};
use std::ops::{Index, IndexMut, Deref, DerefMut};
+use std::slice::{Iter, IterMut};
use term::Cursor;
use ::Rgb;
@@ -60,11 +60,19 @@ impl Grid {
}
}
- pub fn rows(&self) -> usize {
+ pub fn rows(&self) -> vec_deque::Iter<Row> {
+ self.raw.iter()
+ }
+
+ pub fn rows_mut(&mut self) -> vec_deque::IterMut<Row> {
+ self.raw.iter_mut()
+ }
+
+ pub fn num_rows(&self) -> usize {
self.rows
}
- pub fn cols(&self) -> usize {
+ pub fn num_cols(&self) -> usize {
self.cols
}
@@ -130,8 +138,12 @@ impl Row {
Row(vec![Cell::new(' '); columns])
}
- pub fn cols(&self) -> usize {
- self.0.len()
+ pub fn cells(&self) -> Iter<Cell> {
+ self.0.iter()
+ }
+
+ pub fn cells_mut(&mut self) -> IterMut<Cell> {
+ self.0.iter_mut()
}
}