2017-08-20 19:29:23 +00:00
|
|
|
use ansi_term::Style;
|
|
|
|
|
2018-12-07 23:43:31 +00:00
|
|
|
use crate::fs::fields as f;
|
2020-10-10 18:49:46 +00:00
|
|
|
use crate::output::cell::TextCell;
|
2017-05-22 07:48:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
impl f::Blocks {
|
2017-08-20 19:29:23 +00:00
|
|
|
pub fn render<C: Colours>(&self, colours: &C) -> TextCell {
|
2020-10-10 14:30:19 +00:00
|
|
|
match self {
|
|
|
|
Self::Some(blk) => TextCell::paint(colours.block_count(), blk.to_string()),
|
|
|
|
Self::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 {
|
2017-08-26 22:53:47 +00:00
|
|
|
fn block_count(&self) -> Style;
|
|
|
|
fn no_blocks(&self) -> Style;
|
2017-08-20 19:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-22 07:48:32 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
pub mod test {
|
2017-08-26 22:53:47 +00:00
|
|
|
use ansi_term::Style;
|
|
|
|
use ansi_term::Colour::*;
|
|
|
|
|
|
|
|
use super::Colours;
|
2018-12-07 23:43:31 +00:00
|
|
|
use crate::output::cell::TextCell;
|
|
|
|
use crate::fs::fields as f;
|
2017-05-22 07:48:32 +00:00
|
|
|
|
2017-08-20 19:29:23 +00:00
|
|
|
|
2017-08-26 22:53:47 +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
|
|
|
}
|
|
|
|
}
|