mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-12-02 08:18:18 +00:00
Move “coloured file name” into its own function
This commit is contained in:
parent
6b008a6177
commit
70f8ae6e20
@ -1,4 +1,4 @@
|
|||||||
use ansi_term::Style;
|
use ansi_term::{ANSIString, Style};
|
||||||
|
|
||||||
use fs::{File, FileTarget};
|
use fs::{File, FileTarget};
|
||||||
|
|
||||||
@ -22,6 +22,8 @@ mod tree;
|
|||||||
pub fn filename(file: &File, colours: &Colours, links: bool, classify: bool) -> TextCellContents {
|
pub fn filename(file: &File, colours: &Colours, links: bool, classify: bool) -> TextCellContents {
|
||||||
let mut bits = Vec::new();
|
let mut bits = Vec::new();
|
||||||
|
|
||||||
|
// TODO: This long function could do with some splitting up.
|
||||||
|
|
||||||
if file.dir.is_none() {
|
if file.dir.is_none() {
|
||||||
if let Some(parent) = file.path.parent() {
|
if let Some(parent) = file.path.parent() {
|
||||||
let coconut = parent.components().count();
|
let coconut = parent.components().count();
|
||||||
@ -37,7 +39,7 @@ pub fn filename(file: &File, colours: &Colours, links: bool, classify: bool) ->
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !file.name.is_empty() {
|
if !file.name.is_empty() {
|
||||||
bits.push(file_colour(colours, file).paint(file.name.clone()));
|
bits.push(coloured_file_name(file, colours));
|
||||||
}
|
}
|
||||||
|
|
||||||
if links && file.is_link() {
|
if links && file.is_link() {
|
||||||
@ -92,6 +94,10 @@ pub fn filename(file: &File, colours: &Colours, links: bool, classify: bool) ->
|
|||||||
bits.into()
|
bits.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn coloured_file_name<'a>(file: &File, colours: &Colours) -> ANSIString<'a> {
|
||||||
|
file_colour(colours, file).paint(file.name.clone())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn file_colour(colours: &Colours, file: &File) -> Style {
|
pub fn file_colour(colours: &Colours, file: &File) -> Style {
|
||||||
match file {
|
match file {
|
||||||
f if f.is_directory() => colours.filetypes.directory,
|
f if f.is_directory() => colours.filetypes.directory,
|
||||||
|
Loading…
Reference in New Issue
Block a user