diff options
author | nwin <nwin@users.noreply.github.com> | 2015-02-22 13:26:52 +0100 |
---|---|---|
committer | nwin <nwin@users.noreply.github.com> | 2015-02-22 13:26:52 +0100 |
commit | 48b61231658a65473e52d144be43f42a7390735f (patch) | |
tree | e62d2c73f496b7643e91ebf564550e3b2fdc6104 /src/file.rs | |
parent | 376e417c3f8b68dd3e77dbd8359f926861b53c98 (diff) |
Implement display of extended attributes
Diffstat (limited to 'src/file.rs')
-rw-r--r-- | src/file.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/file.rs b/src/file.rs index 32a6e53..c8936d2 100644 --- a/src/file.rs +++ b/src/file.rs @@ -21,6 +21,8 @@ use column::Column::*; use dir::Dir; use filetype::HasType; use options::{SizeFormat, TimeType}; +use attr; +use attr::Attribute; /// This grey value is directly in between white and black, so it's guaranteed /// to show up on either backgrounded terminal. @@ -39,6 +41,7 @@ pub struct File<'a> { pub ext: Option<String>, pub path: Path, pub stat: io::FileStat, + pub attrs: Vec<Attribute>, pub this: Option<Dir>, } @@ -80,6 +83,7 @@ impl<'a> File<'a> { path: path.clone(), dir: parent, stat: stat, + attrs: attr::llist(path).unwrap_or(Vec::new()), name: filename.to_string(), ext: ext(filename.as_slice()), this: this, @@ -192,6 +196,7 @@ impl<'a> File<'a> { path: target_path.clone(), dir: self.dir, stat: stat, + attrs: attr::list(target_path).unwrap_or(Vec::new()), name: filename.to_string(), ext: ext(filename.as_slice()), this: None, @@ -340,6 +345,15 @@ impl<'a> File<'a> { } } + /// Marker indicating that the file contains extended attributes + /// + /// Returns “@” or “ ” depending on wheter the file contains an extented + /// attribute or not. Also returns “ ” in case the attributes cannot be read + /// for some reason. + fn attribute_marker(&self) -> ANSIString { + if self.attrs.len() > 0 { Plain.paint("@") } else { Plain.paint(" ") } + } + /// Generate the "rwxrwxrwx" permissions string, like how ls does it. /// /// Each character is given its own colour. The first three permission @@ -363,6 +377,7 @@ impl<'a> File<'a> { File::permission_bit(&bits, io::OTHER_READ, "r", Yellow.normal()), File::permission_bit(&bits, io::OTHER_WRITE, "w", Red.normal()), File::permission_bit(&bits, io::OTHER_EXECUTE, "x", Green.normal()), + self.attribute_marker() ]).to_string(); Cell { text: string, length: 10 } |