2017-08-20 19:29:23 +00:00
|
|
|
use ansi_term::Style;
|
|
|
|
|
2017-05-22 07:48:32 +00:00
|
|
|
use output::cell::TextCell;
|
|
|
|
use fs::fields as f;
|
|
|
|
|
|
|
|
|
|
|
|
impl f::Blocks {
|
2017-08-20 19:29:23 +00:00
|
|
|
pub fn render<C: Colours>(&self, colours: &C) -> TextCell {
|
2017-05-22 07:48:32 +00:00
|
|
|
match *self {
|
2017-08-20 19:29:23 +00:00
|
|
|
f::Blocks::Some(ref blk) => TextCell::paint(colours.block_count(), blk.to_string()),
|
|
|
|
f::Blocks::None => TextCell::blank(colours.no_blocks()),
|
2017-05-22 07:48:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-20 19:29:23 +00:00
|
|
|
pub trait Colours {
|
|
|
|
fn block_count(&self) -> Style;
|
|
|
|
fn no_blocks(&self) -> Style;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-22 07:48:32 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
pub mod test {
|
2017-08-20 19:29:23 +00:00
|
|
|
use ansi_term::Style;
|
|
|
|
use ansi_term::Colour::*;
|
|
|
|
|
|
|
|
use super::Colours;
|
2017-05-22 07:48:32 +00:00
|
|
|
use output::cell::TextCell;
|
|
|
|
use fs::fields as f;
|
|
|
|
|
2017-08-20 19:29:23 +00:00
|
|
|
|
|
|
|
struct TestColours;
|
|
|
|
|
|
|
|
impl Colours for TestColours {
|
|
|
|
fn block_count(&self) -> Style { Red.blink() }
|
|
|
|
fn no_blocks(&self) -> Style { Green.italic() }
|
|
|
|
}
|
2017-05-22 07:48:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn blocklessness() {
|
|
|
|
let blox = f::Blocks::None;
|
|
|
|
let expected = TextCell::blank(Green.italic());
|
2017-08-20 19:29:23 +00:00
|
|
|
|
|
|
|
assert_eq!(expected, blox.render(&TestColours).into());
|
2017-05-22 07:48:32 +00:00
|
|
|
}
|
|
|
|
|
2017-08-20 19:29:23 +00:00
|
|
|
|
2017-05-22 07:48:32 +00:00
|
|
|
#[test]
|
|
|
|
fn blockfulity() {
|
|
|
|
let blox = f::Blocks::Some(3005);
|
|
|
|
let expected = TextCell::paint_str(Red.blink(), "3005");
|
2017-08-20 19:29:23 +00:00
|
|
|
|
|
|
|
assert_eq!(expected, blox.render(&TestColours).into());
|
2017-05-22 07:48:32 +00:00
|
|
|
}
|
|
|
|
}
|