From 79576b6c0b45868caeef36c5255720a7de6e57de Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Mon, 3 Apr 2017 20:21:55 -0700 Subject: Add better printing for ref test failure The previous format was extremely difficult for a human to parse. --- src/grid.rs | 14 ++++++++++++++ src/util.rs | 15 +++++++++++++++ 2 files changed, 29 insertions(+) (limited to 'src') 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 Grid { self.cols } + pub fn iter_rows(&self) -> slice::Iter> { + self.raw.iter() + } + #[inline] pub fn scroll_down(&mut self, region: Range, positions: index::Line) { for line in IndexRange(region).rev() { @@ -334,6 +338,16 @@ impl Row { } } +impl<'a, T> IntoIterator for &'a Grid { + type Item = &'a Row; + type IntoIter = slice::Iter<'a, Row>; + + #[inline] + fn into_iter(self) -> slice::Iter<'a, Row> { + self.raw.iter() + } +} + impl<'a, T> IntoIterator for &'a Row { 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(pub T); + + impl fmt::Display for Green { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "\x1b[32m{}\x1b[0m", self.0) + } + } + + impl fmt::Debug for Green { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "\x1b[32m{:?}\x1b[0m", self.0) + } + } } #[cfg(test)] -- cgit