summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrabite <rabite@posteo.de>2019-05-07 01:20:42 +0200
committerrabite <rabite@posteo.de>2019-05-07 01:21:22 +0200
commitf92eb544a74a3a1f709911b806ce8d53222fd0d0 (patch)
tree66ac257080dced5a2010920598c5073d6d87f860
parentb9349d62e59adf1003491aa21d9728e7b3beb852 (diff)
add some extra key binds
-rw-r--r--README.md3
-rw-r--r--src/coordinates.rs4
-rw-r--r--src/file_browser.rs39
-rw-r--r--src/listview.rs18
4 files changed, 63 insertions, 1 deletions
diff --git a/README.md b/README.md
index 205ef1a..e04e4e2 100644
--- a/README.md
+++ b/README.md
@@ -50,7 +50,7 @@ If it works on a system not mentioned here, please open an issue. Also feel free
## INSTALLATION:
-Compiling hunter currently requires a nighty Rust compiler!
+Compiling hunter currently requires a nightly Rust compiler!
The easiest way to get a nightly compiler is with [rustup](https://rustup.rs/). If you have rustup installed it will automatically download and use a version that is known to work when you run cargo.
### Install rustup
@@ -127,6 +127,7 @@ By default hunter uses vi-style keybindings. If you use a QWERTY-like keyboard l
| ------------------- | :--------------------------------- |
| j/k (holy: n/p) | move down/up |
| J/K (holy: N/P) | 5x move down/5x move up |
+| ]/[ | move down/up on left column |
| < | move to top |
| > | move to bottom |
| l/h (holy: f/b) | open/go back |
diff --git a/src/coordinates.rs b/src/coordinates.rs
index 6453ad9..0bd2ff7 100644
--- a/src/coordinates.rs
+++ b/src/coordinates.rs
@@ -68,6 +68,10 @@ impl Coordinates {
self.size.xsize()
}
+ pub fn ysize_u(&self) -> usize {
+ (self.ysize() - 1) as usize
+ }
+
pub fn ysize(&self) -> u16 {
self.size.ysize()
}
diff --git a/src/file_browser.rs b/src/file_browser.rs
index 1ca9046..200fea7 100644
--- a/src/file_browser.rs
+++ b/src/file_browser.rs
@@ -420,6 +420,36 @@ impl FileBrowser {
Ok(())
}
+ pub fn move_down_left_widget(&mut self) -> HResult<()> {
+ let left_files_pos = self.left_widget()?.get_selection();
+
+ let next_dir = self.get_left_files()?.get_files()
+ .iter()
+ .skip(left_files_pos + 1)
+ .find(|file| file.is_dir())
+ .cloned().cloned();
+
+ self.main_widget_goto(&next_dir?).log();
+
+ Ok(())
+ }
+
+ pub fn move_up_left_widget(&mut self) -> HResult<()> {
+ let left_files_pos = self.left_widget()?.get_selection();
+ let skip_files = self.get_left_files()?.len() - left_files_pos;
+
+ let next_dir = self.get_left_files()?.get_files()
+ .iter()
+ .rev()
+ .skip(skip_files)
+ .find(|file| file.is_dir())
+ .cloned().cloned();
+
+ self.main_widget_goto(&next_dir?).log();
+
+ Ok(())
+ }
+
pub fn open_bg(&mut self) -> HResult<()> {
let cwd = self.cwd()?;
let file = self.selected_file()?;
@@ -489,6 +519,13 @@ impl FileBrowser {
}
pub fn left_widget_goto(&mut self, dir: &File) -> HResult<()> {
+ // Check if we're in the correct directory already and return
+ // if we are
+ let left_dir = &self.left_widget()?.content.directory;
+ if self.left_widget().is_ok() && left_dir == dir {
+ return Ok(());
+ }
+
let cache = self.fs_cache.clone();
let dir = dir.clone();
@@ -1210,6 +1247,8 @@ impl Widget for FileBrowser {
fn on_key(&mut self, key: Key) -> HResult<()> {
match key {
+ Key::Char(']') => self.move_down_left_widget()?,
+ Key::Char('[') => self.move_up_left_widget()?,
Key::Alt(' ') => self.external_select()?,
Key::Alt('/') => self.external_cd()?,
Key::Char('/') => { self.turbo_cd()?; },
diff --git a/src/listview.rs b/src/listview.rs
index 1d2d44e..ca84e84 100644
--- a/src/listview.rs
+++ b/src/listview.rs
@@ -71,6 +71,8 @@ impl Listable for ListView<Files> {
self.move_down();
self.refresh()?;
},
+ Key::PageUp => self.page_up(),
+ Key::PageDown => self.page_down(),
Key::Char('<') => self.move_top(),
Key::Char('>') => self.move_bottom(),
Key::Char('S') => { self.search_file().log(); }
@@ -164,6 +166,22 @@ where
self.set_selection(lines - 1);
}
+ pub fn page_up(&mut self) {
+ let ysize = self.get_coordinates().unwrap().ysize_u();
+
+ for _ in 0..ysize {
+ self.move_up();
+ }
+ }
+
+ pub fn page_down(&mut self) {
+ let ysize = self.get_coordinates().unwrap().ysize_u();
+
+ for _ in 0..ysize {
+ self.move_down();
+ }
+ }
+
pub fn get_selection(&self) -> usize {
self.selection
}