diff options
author | rabite <rabite@posteo.de> | 2019-02-07 02:25:22 +0100 |
---|---|---|
committer | rabite <rabite@posteo.de> | 2019-02-07 02:25:22 +0100 |
commit | c1eef611e33cfdbea87f82e5d942772c7d468c98 (patch) | |
tree | 995af9efc62ccd6b4804229c6e3614bd5030d624 /src/files.rs | |
parent | 26dc8db216cba4c36c198308bb2efe2d429fecc6 (diff) |
hide hidden files
Diffstat (limited to 'src/files.rs')
-rw-r--r-- | src/files.rs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/files.rs b/src/files.rs index e38af15..728fb71 100644 --- a/src/files.rs +++ b/src/files.rs @@ -21,6 +21,7 @@ pub struct Files { pub sort: SortBy, pub dirs_first: bool, pub reverse: bool, + pub show_hidden: bool } impl Index<usize> for Files { @@ -58,7 +59,7 @@ impl Files { let files: Vec<_> = direntries? .iter() .map(|file| { - //let file = file?; + //let file = file?; let name = file.file_name(); let name = name.to_string_lossy(); let kind = get_kind(&file); @@ -69,7 +70,7 @@ impl Files { let mtime = meta.mtime(); let user = meta.uid(); let group = meta.gid(); - let color = get_color(&path, &meta); + let color = get_color(&path, &meta); File::new(&name, path, kind, size as usize, mtime, color, mode, user, group) }) @@ -81,6 +82,7 @@ impl Files { sort: SortBy::Name, dirs_first: true, reverse: false, + show_hidden: true }; files.sort(); @@ -148,6 +150,23 @@ impl Files { pub fn reverse_sort(&mut self) { self.reverse = !self.reverse } + + pub fn toggle_hidden(&mut self) { + self.show_hidden = !self.show_hidden + } + + pub fn reload_files(&mut self) { + let dir = self.directory.clone(); + let files = Files::new_from_path(&dir.path()).unwrap(); + let files = files + .files + .into_iter() + .skip_while(|f| f.name.starts_with(".") && !self.show_hidden ) + .collect(); + + self.files = files; + } + pub fn len(&self) -> usize { self.files.len() } |