diff options
author | rabite <rabite@posteo.de> | 2019-01-25 11:14:41 +0100 |
---|---|---|
committer | rabite <rabite@posteo.de> | 2019-01-25 11:16:55 +0100 |
commit | f3f783a3a0bc3c96e4678c7fa986dc31bcb8d585 (patch) | |
tree | 2daa9a81e3165bf0fbbd72ddcddbc7f25401ec40 /src/files.rs | |
parent | a1900941ce9a6277f9f0cecd685f8f1c1c6bb705 (diff) |
colored file names
Diffstat (limited to 'src/files.rs')
-rw-r--r-- | src/files.rs | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/files.rs b/src/files.rs index d1422f5..1192659 100644 --- a/src/files.rs +++ b/src/files.rs @@ -5,12 +5,15 @@ use std::ffi::OsStr; use std::cmp::{Ord, Ordering}; pub struct Files(Vec<File>); +use lscolors::{LsColors, Style}; impl Index<usize> for Files { type Output = File; fn index(&self, pos: usize) -> &Self::Output { &self.0[pos] } +lazy_static! { + static ref COLORS: LsColors = LsColors::from_env().unwrap(); } impl PartialOrd for File { @@ -45,8 +48,14 @@ impl Files { let name = name.to_string_lossy(); let kind = get_kind(&file); let path = file.path(); - let size = file.metadata()?.len() / 1024; - let file = File::new(&name, path, kind, size as usize); + let meta = file.metadata()?; + let size = meta.len() / 1024; + let style + = match COLORS.style_for_path_with_metadata(file.path(), Some(&meta)) { + Some(style) => Some(style.clone()), + None => None + }; + let file = File::new(&name, path, kind, size as usize, style); match kind { Kind::Directory => dirs.push(file), _ => files.push(file), @@ -84,6 +93,7 @@ pub struct File { pub path: PathBuf, pub size: Option<usize>, pub kind: Kind, + pub style: Option<Style> // owner: Option<String>, // group: Option<String>, // flags: Option<String>, @@ -93,12 +103,17 @@ pub struct File { impl File { - pub fn new(name: &str, path: PathBuf, kind: Kind, size: usize) -> File { + pub fn new(name: &str, + path: PathBuf, + kind: Kind, + size: usize, + style: Option<Style>) -> File { File { name: name.to_string(), path: path, size: Some(size), - kind: kind + kind: kind, + style: style // owner: None, // group: None, // flags: None, |