add some extra key binds

This commit is contained in:
rabite 2019-05-07 01:20:42 +02:00
parent b9349d62e5
commit f92eb544a7
4 changed files with 63 additions and 1 deletions

View File

@ -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 |

View File

@ -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()
}

View File

@ -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()?; },

View File

@ -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
}