diff options
author | rabite <rabite@posteo.de> | 2019-02-01 14:36:48 +0100 |
---|---|---|
committer | rabite <rabite@posteo.de> | 2019-02-01 14:36:48 +0100 |
commit | 23e699234a570c031572bed029ff63b5a2eaed3a (patch) | |
tree | 3762c9cd2178a597e8735ec8084aa25144767816 /src/files.rs | |
parent | ea77d6f45a55bf1992c5b5237c73b8ca92bb2114 (diff) |
add flaceholder for empty dir
Diffstat (limited to 'src/files.rs')
-rw-r--r-- | src/files.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/files.rs b/src/files.rs index e03c3a0..93120d1 100644 --- a/src/files.rs +++ b/src/files.rs @@ -77,6 +77,11 @@ impl Files { }; files.sort(); + + if files.files.len() == 0 { + files.files = vec![File::new_placeholder(&path)?]; + } + Ok(files) } @@ -133,6 +138,7 @@ pub enum Kind { File, Link, Pipe, + Placeholder } impl std::fmt::Display for SortBy { @@ -203,6 +209,13 @@ impl File { Ok(File::new(&name, pathbuf, kind, size as usize, mtime, color)) } + pub fn new_placeholder(path: &Path) -> Result<File, Box<Error>> { + let mut file = File::new_from_path(path)?; + file.name = "<empty>".to_string(); + file.kind = Kind::Placeholder; + Ok(file) + } + pub fn calculate_size(&self) -> (usize, String) { let mut unit = 0; let mut size = self.size.unwrap(); @@ -236,6 +249,19 @@ impl File { self.kind == Kind::Directory } + pub fn read_dir(&self) -> Result<Files, Box<Error>> { + match self.kind { + Kind::Placeholder => { + let e: Box<Error> + = From::from("placeholder".to_string()); + Err(e) + }, + _ => Files::new_from_path(&self.path) + } + + } + + pub fn path(&self) -> PathBuf { self.path.clone() } |