1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
use ansi_term::Style;
use colours::Colours;
use file::File;
use filetype::file_colour;
pub use self::cell::{TextCell, TextCellContents, DisplayWidth};
pub use self::details::Details;
pub use self::grid::Grid;
pub use self::lines::Lines;
pub use self::grid_details::GridDetails;
mod grid;
pub mod details;
mod lines;
mod grid_details;
pub mod column;
mod cell;
pub fn filename(file: File, colours: &Colours, links: bool) -> TextCellContents {
if links && file.is_link() {
symlink_filename(file, colours)
}
else {
vec![
file_colour(colours, &file).paint(file.name)
].into()
}
}
fn symlink_filename(file: File, colours: &Colours) -> TextCellContents {
match file.link_target() {
Ok(target) => vec![
file_colour(colours, &file).paint(file.name),
Style::default().paint(" "),
colours.punctuation.paint("->"),
Style::default().paint(" "),
colours.symlink_path.paint(target.path_prefix()),
file_colour(colours, &target).paint(target.name)
].into(),
Err(filename) => vec![
file_colour(colours, &file).paint(file.name),
Style::default().paint(" "),
colours.broken_arrow.paint("->"),
Style::default().paint(" "),
colours.broken_filename.paint(filename),
].into(),
}
}
|