2017-08-20 19:29:23 +00:00
|
|
|
use ansi_term::Style;
|
|
|
|
use locale::Numeric as NumericLocale;
|
|
|
|
|
2017-05-22 07:43:09 +00:00
|
|
|
use output::cell::TextCell;
|
|
|
|
use fs::fields as f;
|
|
|
|
|
|
|
|
|
|
|
|
impl f::Links {
|
2017-08-20 19:29:23 +00:00
|
|
|
pub fn render<C: Colours>(&self, colours: &C, numeric: &NumericLocale) -> TextCell {
|
|
|
|
let style = if self.multiple { colours.multi_link_file() }
|
|
|
|
else { colours.normal() };
|
2017-05-22 07:43:09 +00:00
|
|
|
|
|
|
|
TextCell::paint(style, numeric.format_int(self.count))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-20 19:29:23 +00:00
|
|
|
pub trait Colours {
|
2017-08-26 22:53:47 +00:00
|
|
|
fn normal(&self) -> Style;
|
|
|
|
fn multi_link_file(&self) -> Style;
|
2017-08-20 19:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-22 07:43:09 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
pub mod test {
|
2017-08-26 22:53:47 +00:00
|
|
|
use super::Colours;
|
2017-05-22 07:43:09 +00:00
|
|
|
use output::cell::{TextCell, DisplayWidth};
|
|
|
|
use fs::fields as f;
|
|
|
|
|
|
|
|
use ansi_term::Colour::*;
|
2017-08-20 19:29:23 +00:00
|
|
|
use ansi_term::Style;
|
2017-05-22 07:43:09 +00:00
|
|
|
use locale;
|
2017-08-26 22:53:47 +00:00
|
|
|
|
|
|
|
|
2017-08-20 19:29:23 +00:00
|
|
|
struct TestColours;
|
2017-08-26 22:53:47 +00:00
|
|
|
|
2017-08-20 19:29:23 +00:00
|
|
|
impl Colours for TestColours {
|
2017-08-26 22:53:47 +00:00
|
|
|
fn normal(&self) -> Style { Blue.normal() }
|
|
|
|
fn multi_link_file(&self) -> Style { Blue.on(Red) }
|
2017-08-20 19:29:23 +00:00
|
|
|
}
|
2017-05-22 07:43:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn regular_file() {
|
|
|
|
let stati = f::Links {
|
|
|
|
count: 1,
|
|
|
|
multiple: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
let expected = TextCell {
|
|
|
|
width: DisplayWidth::from(1),
|
|
|
|
contents: vec![ Blue.paint("1") ].into(),
|
|
|
|
};
|
|
|
|
|
2017-08-20 19:29:23 +00:00
|
|
|
assert_eq!(expected, stati.render(&TestColours, &locale::Numeric::english()).into());
|
2017-05-22 07:43:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn regular_directory() {
|
|
|
|
let stati = f::Links {
|
|
|
|
count: 3005,
|
|
|
|
multiple: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
let expected = TextCell {
|
|
|
|
width: DisplayWidth::from(5),
|
|
|
|
contents: vec![ Blue.paint("3,005") ].into(),
|
|
|
|
};
|
|
|
|
|
2017-08-20 19:29:23 +00:00
|
|
|
assert_eq!(expected, stati.render(&TestColours, &locale::Numeric::english()).into());
|
2017-05-22 07:43:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn popular_file() {
|
|
|
|
let stati = f::Links {
|
|
|
|
count: 3005,
|
|
|
|
multiple: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
let expected = TextCell {
|
|
|
|
width: DisplayWidth::from(5),
|
|
|
|
contents: vec![ Blue.on(Red).paint("3,005") ].into(),
|
|
|
|
};
|
|
|
|
|
2017-08-20 19:29:23 +00:00
|
|
|
assert_eq!(expected, stati.render(&TestColours, &locale::Numeric::english()).into());
|
2017-05-22 07:43:09 +00:00
|
|
|
}
|
|
|
|
}
|