summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/grid.rs14
-rw-r--r--src/util.rs15
-rw-r--r--tests/ref.rs18
3 files changed, 46 insertions, 1 deletions
diff --git a/src/grid.rs b/src/grid.rs
index 1c5b94c4..af3a8ae4 100644
--- a/src/grid.rs
+++ b/src/grid.rs
@@ -146,6 +146,10 @@ impl<T> Grid<T> {
self.cols
}
+ pub fn iter_rows(&self) -> slice::Iter<Row<T>> {
+ self.raw.iter()
+ }
+
#[inline]
pub fn scroll_down(&mut self, region: Range<index::Line>, positions: index::Line) {
for line in IndexRange(region).rev() {
@@ -334,6 +338,16 @@ impl<T> Row<T> {
}
}
+impl<'a, T> IntoIterator for &'a Grid<T> {
+ type Item = &'a Row<T>;
+ type IntoIter = slice::Iter<'a, Row<T>>;
+
+ #[inline]
+ fn into_iter(self) -> slice::Iter<'a, Row<T>> {
+ self.raw.iter()
+ }
+}
+
impl<'a, T> IntoIterator for &'a Row<T> {
type Item = &'a T;
type IntoIter = slice::Iter<'a, T>;
diff --git a/src/util.rs b/src/util.rs
index 3452e5b2..7227f1a0 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -77,6 +77,21 @@ pub mod fmt {
/// Write a `Display` or `Debug` escaped with Yellow
pub struct Yellow => "33";
}
+
+ /// Write a `Display` or `Debug` escaped with Red
+ pub struct Green<T>(pub T);
+
+ impl<T: fmt::Display> fmt::Display for Green<T> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "\x1b[32m{}\x1b[0m", self.0)
+ }
+ }
+
+ impl<T: fmt::Debug> fmt::Debug for Green<T> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "\x1b[32m{:?}\x1b[0m", self.0)
+ }
+ }
}
#[cfg(test)]
diff --git a/tests/ref.rs b/tests/ref.rs
index 98f1ed4a..7a78ec73 100644
--- a/tests/ref.rs
+++ b/tests/ref.rs
@@ -7,9 +7,11 @@ use std::path::Path;
use alacritty::Grid;
use alacritty::Term;
+use alacritty::ansi;
+use alacritty::index::{Line, Column};
use alacritty::term::Cell;
use alacritty::term::SizeInfo;
-use alacritty::ansi;
+use alacritty::util::fmt::{Red, Green};
macro_rules! ref_tests {
($($name:ident)*) => {
@@ -71,5 +73,19 @@ fn ref_test(dir: &Path) {
parser.advance(&mut terminal, byte, &mut io::sink());
}
+ if grid != *terminal.grid() {
+ for (i, row) in terminal.grid().iter_rows().enumerate() {
+ for (j, cell) in row.iter().enumerate() {
+ let original_cell = &grid[Line(i)][Column(j)];
+ if *original_cell != *cell {
+ println!("[{i}][{j}] {original:?} => {now:?}",
+ i=i, j=j, original=Green(original_cell), now=Red(cell));
+ }
+ }
+ }
+
+ panic!("Ref test failed; grid doesn't match");
+ }
+
assert_eq!(grid, *terminal.grid());
}