mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-23 12:32:00 +00:00
Monday morning Links extraction
This commit is contained in:
parent
f0cf5b4538
commit
eec81c4f48
81
src/output/render/links.rs
Normal file
81
src/output/render/links.rs
Normal file
@ -0,0 +1,81 @@
|
||||
use output::cell::TextCell;
|
||||
use output::colours::Colours;
|
||||
use fs::fields as f;
|
||||
|
||||
use locale;
|
||||
|
||||
|
||||
impl f::Links {
|
||||
pub fn render(&self, colours: &Colours, numeric: &locale::Numeric) -> TextCell {
|
||||
let style = if self.multiple { colours.links.multi_link_file }
|
||||
else { colours.links.normal };
|
||||
|
||||
TextCell::paint(style, numeric.format_int(self.count))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod test {
|
||||
use output::details::Details;
|
||||
use output::cell::{TextCell, DisplayWidth};
|
||||
use fs::fields as f;
|
||||
|
||||
use ansi_term::Colour::*;
|
||||
use locale;
|
||||
|
||||
|
||||
#[test]
|
||||
fn regular_file() {
|
||||
let mut details = Details::default();
|
||||
details.colours.links.normal = Blue.normal();
|
||||
|
||||
let stati = f::Links {
|
||||
count: 1,
|
||||
multiple: false,
|
||||
};
|
||||
|
||||
let expected = TextCell {
|
||||
width: DisplayWidth::from(1),
|
||||
contents: vec![ Blue.paint("1") ].into(),
|
||||
};
|
||||
|
||||
assert_eq!(expected, stati.render(&details.colours, &locale::Numeric::english()).into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn regular_directory() {
|
||||
let mut details = Details::default();
|
||||
details.colours.links.normal = Blue.normal();
|
||||
|
||||
let stati = f::Links {
|
||||
count: 3005,
|
||||
multiple: false,
|
||||
};
|
||||
|
||||
let expected = TextCell {
|
||||
width: DisplayWidth::from(5),
|
||||
contents: vec![ Blue.paint("3,005") ].into(),
|
||||
};
|
||||
|
||||
assert_eq!(expected, stati.render(&details.colours, &locale::Numeric::english()).into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn popular_file() {
|
||||
let mut details = Details::default();
|
||||
details.colours.links.multi_link_file = Blue.on(Red);
|
||||
|
||||
let stati = f::Links {
|
||||
count: 3005,
|
||||
multiple: true,
|
||||
};
|
||||
|
||||
let expected = TextCell {
|
||||
width: DisplayWidth::from(5),
|
||||
contents: vec![ Blue.on(Red).paint("3,005") ].into(),
|
||||
};
|
||||
|
||||
assert_eq!(expected, stati.render(&details.colours, &locale::Numeric::english()).into());
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
mod git;
|
||||
mod groups;
|
||||
mod links;
|
||||
mod permissions;
|
||||
mod size;
|
||||
mod users;
|
||||
@ -13,15 +14,6 @@ use datetime::fmt::DateFormat;
|
||||
use locale;
|
||||
|
||||
|
||||
impl f::Links {
|
||||
pub fn render(&self, colours: &Colours, numeric: &locale::Numeric) -> TextCell {
|
||||
let style = if self.multiple { colours.links.multi_link_file }
|
||||
else { colours.links.normal };
|
||||
|
||||
TextCell::paint(style, numeric.format_int(self.count))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl f::Blocks {
|
||||
pub fn render(&self, colours: &Colours) -> TextCell {
|
||||
|
Loading…
Reference in New Issue
Block a user