diff options
-rw-r--r-- | config/keymap.toml | 29 | ||||
-rw-r--r-- | src/commands/cursor_move.rs | 97 | ||||
-rw-r--r-- | src/commands/mod.rs | 12 | ||||
-rw-r--r-- | src/commands/search.rs | 6 | ||||
-rw-r--r-- | src/commands/selection.rs | 4 | ||||
-rw-r--r-- | src/commands/set_mode.rs | 4 |
6 files changed, 80 insertions, 72 deletions
diff --git a/config/keymap.toml b/config/keymap.toml index a3c3724..854b69b 100644 --- a/config/keymap.toml +++ b/config/keymap.toml @@ -9,22 +9,22 @@ command = "reload_dir_list" [[mapcommand]] keys = [ "Up" ] -command = "cursor_move" -args = [ "-1" ] +command = "cursor_move_up" +args = [ "1" ] [[mapcommand]] keys = [ "k" ] -command = "cursor_move" -args = [ "-1" ] +command = "cursor_move_up" +args = [ "1" ] [[mapcommand]] keys = [ "Down" ] -command = "cursor_move" +command = "cursor_move_down" args = [ "1" ] [[mapcommand]] keys = [ "j" ] -command = "cursor_move" +command = "cursor_move_down" args = [ "1" ] [[mapcommand]] @@ -140,6 +140,11 @@ command = "mkdir" [[mapcommand]] +keys = [ "g", "P" ] +command = "cd" +args = [ "~/Pictures" ] + +[[mapcommand]] keys = [ "g", "r" ] command = "cd" args = [ "/" ] @@ -160,6 +165,12 @@ command = "cd" args = [ "~/Downloads" ] [[mapcommand]] +keys = [ "g", "p" ] +command = "cd" +args = [ "~/Pictures" ] + + +[[mapcommand]] keys = [ "/" ] command = "search" @@ -196,7 +207,7 @@ command = "set_mode" ## Features not yet implemented -[[mapcommand]] -keys = [ "b", "b" ] -command = "bulk_rename" +## [[mapcommand]] +## keys = [ "b", "b" ] +## command = "bulk_rename" diff --git a/src/commands/cursor_move.rs b/src/commands/cursor_move.rs index e02c21f..049657a 100644 --- a/src/commands/cursor_move.rs +++ b/src/commands/cursor_move.rs @@ -3,64 +3,61 @@ use crate::context::JoshutoContext; use crate::error::JoshutoError; use crate::window::JoshutoView; -pub struct CursorMove; - -impl CursorMove { - pub fn cursor_move(mut new_index: usize, context: &mut JoshutoContext, view: &JoshutoView) { - let curr_tab = &mut context.tabs[context.curr_tab_index]; - - match curr_tab.curr_list.index { - None => {} - Some(_) => { - let dir_len = curr_tab.curr_list.contents.len(); - /* - if index == dir_len - 1 { - return; - } - */ - if new_index >= dir_len { - new_index = dir_len - 1; - } - curr_tab.curr_list.index = Some(new_index); + +pub fn cursor_move(mut new_index: usize, context: &mut JoshutoContext, view: &JoshutoView) { + let curr_tab = &mut context.tabs[context.curr_tab_index]; + + match curr_tab.curr_list.index { + None => {} + Some(_) => { + let dir_len = curr_tab.curr_list.contents.len(); + /* + if index == dir_len - 1 { + return; } + */ + if new_index >= dir_len { + new_index = dir_len - 1; + } + curr_tab.curr_list.index = Some(new_index); } - - curr_tab.refresh_curr(&view.mid_win, context.config_t.scroll_offset); - curr_tab.refresh_path_status( - &view.top_win, - &context.username, - &context.hostname, - context.config_t.tilde_in_titlebar, - ); - curr_tab.refresh_file_status(&view.bot_win); - curr_tab.refresh_preview(&view.right_win, &context.config_t); - ncurses::doupdate(); } + + curr_tab.refresh_curr(&view.mid_win, context.config_t.scroll_offset); + curr_tab.refresh_path_status( + &view.top_win, + &context.username, + &context.hostname, + context.config_t.tilde_in_titlebar, + ); + curr_tab.refresh_file_status(&view.bot_win); + curr_tab.refresh_preview(&view.right_win, &context.config_t); + ncurses::doupdate(); } #[derive(Clone, Debug)] -pub struct CursorMoveInc { +pub struct CursorMoveDown { movement: usize, } -impl CursorMoveInc { +impl CursorMoveDown { pub fn new(movement: usize) -> Self { - CursorMoveInc { movement } + CursorMoveDown { movement } } pub const fn command() -> &'static str { - "cursor_move_increment" + "cursor_move_up" } } -impl JoshutoCommand for CursorMoveInc {} +impl JoshutoCommand for CursorMoveDown {} -impl std::fmt::Display for CursorMoveInc { +impl std::fmt::Display for CursorMoveDown { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{} {}", Self::command(), self.movement) } } -impl JoshutoRunnable for CursorMoveInc { +impl JoshutoRunnable for CursorMoveDown { fn execute( &self, context: &mut JoshutoContext, @@ -71,35 +68,35 @@ impl JoshutoRunnable for CursorMoveInc { curr_list.index.map(|idx| idx + self.movement) }; if let Some(s) = movement { - CursorMove::cursor_move(s, context, view) + cursor_move(s, context, view) } Ok(()) } } #[derive(Clone, Debug)] -pub struct CursorMoveDec { +pub struct CursorMoveUp { movement: usize, } -impl CursorMoveDec { +impl CursorMoveUp { pub fn new(movement: usize) -> Self { - CursorMoveDec { movement } + CursorMoveUp { movement } } pub const fn command() -> &'static str { - "cursor_move_increment" + "cursor_move_down" } } -impl JoshutoCommand for CursorMoveDec {} +impl JoshutoCommand for CursorMoveUp {} -impl std::fmt::Display for CursorMoveDec { +impl std::fmt::Display for CursorMoveUp { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{} {}", Self::command(), self.movement) } } -impl JoshutoRunnable for CursorMoveDec { +impl JoshutoRunnable for CursorMoveUp { fn execute( &self, context: &mut JoshutoContext, @@ -113,7 +110,7 @@ impl JoshutoRunnable for CursorMoveDec { } }); if let Some(s) = movement { - CursorMove::cursor_move(s, context, view); + cursor_move(s, context, view); } Ok(()) } @@ -153,7 +150,7 @@ impl JoshutoRunnable for CursorMovePageUp { .map(|x| if x > half_page { x - half_page } else { 0 }) }; if let Some(s) = movement { - CursorMove::cursor_move(s, context, view); + cursor_move(s, context, view); } Ok(()) } @@ -199,7 +196,7 @@ impl JoshutoRunnable for CursorMovePageDown { }; if let Some(s) = movement { - CursorMove::cursor_move(s, context, view); + cursor_move(s, context, view); } Ok(()) } @@ -241,7 +238,7 @@ impl JoshutoRunnable for CursorMoveHome { }; if let Some(s) = movement { - CursorMove::cursor_move(s, context, view); + cursor_move(s, context, view); } Ok(()) } @@ -283,7 +280,7 @@ impl JoshutoRunnable for CursorMoveEnd { }; if let Some(s) = movement { - CursorMove::cursor_move(s, context, view); + cursor_move(s, context, view); } Ok(()) } diff --git a/src/commands/mod.rs b/src/commands/mod.rs index d091cd4..2f72640 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -17,8 +17,8 @@ mod tab_switch; pub use self::change_directory::ChangeDirectory; pub use self::cursor_move::{ - CursorMove, CursorMoveDec, CursorMoveEnd, CursorMoveHome, CursorMoveInc, CursorMovePageDown, - CursorMovePageUp, + CursorMoveDown, CursorMoveEnd, CursorMoveHome, CursorMovePageDown, CursorMovePageUp, + CursorMoveUp }; pub use self::delete_files::DeleteFiles; pub use self::file_operations::{CopyFiles, CutFiles, FileOperationThread, PasteFiles}; @@ -92,12 +92,12 @@ pub fn from_args(command: &str, args: Option<&Vec<String>>) -> Option<Box<Joshut } "close_tab" => Some(Box::new(self::CloseTab::new())), "copy_files" => Some(Box::new(self::CopyFiles::new())), - "cursor_move_inc" => { + "cursor_move_down" => { if let Some(args) = args { if !args.is_empty() { match args[0].parse::<usize>() { Ok(s) => { - return Some(Box::new(self::CursorMoveInc::new(s))); + return Some(Box::new(self::CursorMoveUp::new(s))); } Err(e) => { eprintln!("{}", e); @@ -107,12 +107,12 @@ pub fn from_args(command: &str, args: Option<&Vec<String>>) -> Option<Box<Joshut } None } - "cursor_move_dec" => { + "cursor_move_up" => { if let Some(args) = args { if !args.is_empty() { match args[0].parse::<usize>() { Ok(s) => { - return Some(Box::new(self::CursorMoveDec::new(s))); + return Some(Box::new(self::CursorMoveDown::new(s))); } Err(e) => { eprintln!("{}", e); diff --git a/src/commands/search.rs b/src/commands/search.rs index fa48ac3..9dc45d3 100644 --- a/src/commands/search.rs +++ b/src/commands/search.rs @@ -1,7 +1,7 @@ use lazy_static::lazy_static; use std::sync::Mutex; -use crate::commands::{CursorMove, JoshutoCommand, JoshutoRunnable}; +use crate::commands::{cursor_move, JoshutoCommand, JoshutoRunnable}; use crate::context::JoshutoContext; use crate::error::JoshutoError; use crate::tab::JoshutoTab; @@ -95,7 +95,7 @@ impl JoshutoRunnable for Search { let index = Self::search(&context.tabs[context.curr_tab_index], &user_input); if let Some(index) = index { - CursorMove::cursor_move(index, context, view); + cursor_move::cursor_move(index, context, view); } let mut data = SEARCH_PATTERN.lock().unwrap(); *data = Some(user_input); @@ -114,7 +114,7 @@ fn search_with_func( if let Some(s) = (*data).as_ref() { let index = search_func(&context.tabs[context.curr_tab_index], s); if let Some(index) = index { - CursorMove::cursor_move(index, context, view); + cursor_move::cursor_move(index, context, view); } ncurses::doupdate(); } diff --git a/src/commands/selection.rs b/src/commands/selection.rs index d1365db..5133d07 100644 --- a/src/commands/selection.rs +++ b/src/commands/selection.rs @@ -1,4 +1,4 @@ -use crate::commands::{CursorMoveInc, JoshutoCommand, JoshutoRunnable}; +use crate::commands::{CursorMoveDown, JoshutoCommand, JoshutoRunnable}; use crate::context::JoshutoContext; use crate::error::JoshutoError; use crate::window::JoshutoView; @@ -42,7 +42,7 @@ impl JoshutoRunnable for SelectFiles { let curr_list = &mut context.tabs[context.curr_tab_index].curr_list; if let Some(s) = curr_list.get_curr_mut() { s.selected = !s.selected; - return CursorMoveInc::new(1).execute(context, view); + return CursorMoveDown::new(1).execute(context, view); } } return Ok(()); diff --git a/src/commands/set_mode.rs b/src/commands/set_mode.rs index bef6fe5..955f883 100644 --- a/src/commands/set_mode.rs +++ b/src/commands/set_mode.rs @@ -1,4 +1,4 @@ -use crate::commands::{CursorMoveInc, JoshutoCommand, JoshutoRunnable}; +use crate::commands::{CursorMoveDown, JoshutoCommand, JoshutoRunnable}; use crate::context::JoshutoContext; use crate::error::JoshutoError; use crate::structs::JoshutoDirEntry; @@ -89,7 +89,7 @@ impl JoshutoRunnable for SetMode { mode_string.remove(0); self.set_mode(file, mode_string); - CursorMoveInc::new(1).execute(context, view) + CursorMoveDown::new(1).execute(context, view) } else { Ok(()) } |