feature(strider): Allow to Hide Hidden Files (#203)

closes #197

default keybinding = '.'
default view = shows hidden files

Alternative:
Hide hidden files by default.
This commit is contained in:
a-kenji 2021-02-23 20:25:02 +01:00 committed by GitHub
parent 8d923ec6fd
commit 683c152fa2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View file

@ -61,6 +61,12 @@ impl ZellijTile for State {
self.path.pop();
refresh_directory(self);
}
Key::Char('.') => {
self.toggle_hidden_files();
refresh_directory(self);
}
_ => (),
};
}
@ -80,6 +86,7 @@ fn refresh_directory(state: &mut State) {
}
})
.ok()
.filter(|d| !d.is_hidden_file() || !state.hide_hidden_files)
})
.collect();

View file

@ -6,6 +6,7 @@ pub struct State {
pub path: PathBuf,
pub files: Vec<FsEntry>,
pub cursor_hist: HashMap<PathBuf, (usize, usize)>,
pub hide_hidden_files: bool,
}
impl State {
@ -21,6 +22,9 @@ impl State {
pub fn scroll(&self) -> usize {
self.cursor_hist.get(&self.path).unwrap_or(&(0, 0)).1
}
pub fn toggle_hidden_files(&mut self) {
self.hide_hidden_files = !self.hide_hidden_files;
}
}
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone)]
@ -52,4 +56,8 @@ impl FsEntry {
[name, padding, info].concat()
}
}
pub fn is_hidden_file(&self) -> bool {
self.name().chars().nth(0).unwrap() == '.'.into()
}
}