diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2020-02-16 15:45:05 -0500 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2020-02-16 15:50:25 -0500 |
commit | 98d0ce7e70f9febf804cda7473f5e9f7f180fe91 (patch) | |
tree | c8c8dd60d9e6502202b910e64f79cd75b933d05d /src/commands | |
parent | d788f8d740be85bb014ddfa005156723f0a31e99 (diff) |
remove ncurses dependency
- clean up code
- update theme config
- fix localstate tracking file selection not selecting proper files
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/bulk_rename.rs | 2 | ||||
-rw-r--r-- | src/commands/change_directory.rs | 5 | ||||
-rw-r--r-- | src/commands/command_line.rs | 1 | ||||
-rw-r--r-- | src/commands/cursor_move.rs | 28 | ||||
-rw-r--r-- | src/commands/file_ops/copy.rs | 11 | ||||
-rw-r--r-- | src/commands/file_ops/cut.rs | 11 | ||||
-rw-r--r-- | src/commands/open_file.rs | 2 | ||||
-rw-r--r-- | src/commands/parent_directory.rs | 9 | ||||
-rw-r--r-- | src/commands/reload_dir.rs | 5 | ||||
-rw-r--r-- | src/commands/rename_file.rs | 3 | ||||
-rw-r--r-- | src/commands/search.rs | 17 |
11 files changed, 45 insertions, 49 deletions
diff --git a/src/commands/bulk_rename.rs b/src/commands/bulk_rename.rs index c2e127f..9f67106 100644 --- a/src/commands/bulk_rename.rs +++ b/src/commands/bulk_rename.rs @@ -132,7 +132,7 @@ impl std::fmt::Display for BulkRename { } impl JoshutoRunnable for BulkRename { - fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { + fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { Self::bulk_rename(context)?; ReloadDirList::reload(context.curr_tab_index, context)?; Ok(()) diff --git a/src/commands/change_directory.rs b/src/commands/change_directory.rs index 5f30c36..1897b90 100644 --- a/src/commands/change_directory.rs +++ b/src/commands/change_directory.rs @@ -32,7 +32,6 @@ impl ChangeDirectory { pub fn change_directories( path: &path::Path, context: &mut JoshutoContext, - backend: &mut TuiBackend, ) -> std::io::Result<()> { Self::cd(path, context)?; @@ -55,8 +54,8 @@ impl std::fmt::Display for ChangeDirectory { impl JoshutoRunnable for ChangeDirectory { fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { - Self::change_directories(&self.path, context, backend)?; - LoadChild::load_child(context, backend); + Self::change_directories(&self.path, context)?; + LoadChild::load_child(context)?; Ok(()) } diff --git a/src/commands/command_line.rs b/src/commands/command_line.rs index 1ca2c14..5795e5d 100644 --- a/src/commands/command_line.rs +++ b/src/commands/command_line.rs @@ -56,7 +56,6 @@ impl std::fmt::Display for CommandLine { impl JoshutoRunnable for CommandLine { fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { let res = self.readline(context, backend); - ncurses::doupdate(); res } } diff --git a/src/commands/cursor_move.rs b/src/commands/cursor_move.rs index 5fee941..a0b7522 100644 --- a/src/commands/cursor_move.rs +++ b/src/commands/cursor_move.rs @@ -6,14 +6,14 @@ use crate::error::JoshutoResult; use crate::history::DirectoryHistory; use crate::ui::TuiBackend; -pub fn cursor_move(new_index: usize, context: &mut JoshutoContext, backend: &mut TuiBackend) { +pub fn cursor_move(new_index: usize, context: &mut JoshutoContext) { let mut new_index = new_index; let curr_tab = &mut context.tabs[context.curr_tab_index]; let mut path: Option<PathBuf> = None; if let Some(curr_list) = curr_tab.curr_list_mut() { - if let Some(index) = curr_list.index { + if let Some(_) = curr_list.index { let dir_len = curr_list.contents.len(); if new_index >= dir_len { new_index = dir_len - 1; @@ -58,14 +58,14 @@ impl std::fmt::Display for CursorMoveDown { } impl JoshutoRunnable for CursorMoveDown { - fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { + fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { let movement = match context.curr_tab_ref().curr_list_ref() { Some(curr_list) => curr_list.index.map(|idx| idx + self.movement), None => None, }; if let Some(s) = movement { - cursor_move(s, context, backend) + cursor_move(s, context) } Ok(()) } @@ -94,7 +94,7 @@ impl std::fmt::Display for CursorMoveUp { } impl JoshutoRunnable for CursorMoveUp { - fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { + fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { let movement = match context.curr_tab_ref().curr_list_ref() { Some(curr_list) => curr_list.index.map(|idx| { if idx > self.movement { @@ -107,7 +107,7 @@ impl JoshutoRunnable for CursorMoveUp { }; if let Some(s) = movement { - cursor_move(s, context, backend) + cursor_move(s, context) } Ok(()) } @@ -134,7 +134,7 @@ impl std::fmt::Display for CursorMovePageUp { } impl JoshutoRunnable for CursorMovePageUp { - fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { + fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { let movement = match context.curr_tab_ref().curr_list_ref() { Some(curr_list) => { let half_page = 10; @@ -146,7 +146,7 @@ impl JoshutoRunnable for CursorMovePageUp { }; if let Some(s) = movement { - cursor_move(s, context, backend); + cursor_move(s, context); } Ok(()) } @@ -173,7 +173,7 @@ impl std::fmt::Display for CursorMovePageDown { } impl JoshutoRunnable for CursorMovePageDown { - fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { + fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { let movement = match context.curr_tab_ref().curr_list_ref() { Some(curr_list) => { let dir_len = curr_list.contents.len(); @@ -190,7 +190,7 @@ impl JoshutoRunnable for CursorMovePageDown { }; if let Some(s) = movement { - cursor_move(s, context, backend); + cursor_move(s, context); } Ok(()) } @@ -217,7 +217,7 @@ impl std::fmt::Display for CursorMoveHome { } impl JoshutoRunnable for CursorMoveHome { - fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { + fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { let movement: Option<usize> = { let len = context.curr_tab_mut().curr_list.contents.len(); if len == 0 { @@ -228,7 +228,7 @@ impl JoshutoRunnable for CursorMoveHome { }; if let Some(s) = movement { - cursor_move(s, context, backend); + cursor_move(s, context); } Ok(()) } @@ -255,7 +255,7 @@ impl std::fmt::Display for CursorMoveEnd { } impl JoshutoRunnable for CursorMoveEnd { - fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { + fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { let movement: Option<usize> = { let len = context.curr_tab_mut().curr_list.contents.len(); if len == 0 { @@ -266,7 +266,7 @@ impl JoshutoRunnable for CursorMoveEnd { }; if let Some(s) = movement { - cursor_move(s, context, backend); + cursor_move(s, context); } Ok(()) } diff --git a/src/commands/file_ops/copy.rs b/src/commands/file_ops/copy.rs index 2551321..a7edbef 100644 --- a/src/commands/file_ops/copy.rs +++ b/src/commands/file_ops/copy.rs @@ -28,9 +28,14 @@ impl std::fmt::Display for CopyFiles { impl JoshutoRunnable for CopyFiles { fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { let curr_tab = context.curr_tab_ref(); - LocalState::repopulated_selected_files(&curr_tab.curr_list)?; - LocalState::set_file_op(FileOp::Copy); - LocalState::set_tab_src(context.curr_tab_index); + match curr_tab.curr_list_ref() { + Some(list) => { + LocalState::repopulated_selected_files(list)?; + LocalState::set_file_op(FileOp::Copy); + LocalState::set_tab_src(context.curr_tab_index); + } + None => {} + } Ok(()) } } diff --git a/src/commands/file_ops/cut.rs b/src/commands/file_ops/cut.rs index d77f157..42ec7f2 100644 --- a/src/commands/file_ops/cut.rs +++ b/src/commands/file_ops/cut.rs @@ -28,9 +28,14 @@ impl std::fmt::Display for CutFiles { impl JoshutoRunnable for CutFiles { fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { let curr_tab = context.curr_tab_ref(); - LocalState::repopulated_selected_files(&curr_tab.curr_list)?; - LocalState::set_file_op(FileOp::Cut); - LocalState::set_tab_src(context.curr_tab_index); + match curr_tab.curr_list_ref() { + Some(list) => { + LocalState::repopulated_selected_files(list)?; + LocalState::set_file_op(FileOp::Cut); + LocalState::set_tab_src(context.curr_tab_index); + } + None => {} + } Ok(()) } } diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs index 501eb67..4f29432 100644 --- a/src/commands/open_file.rs +++ b/src/commands/open_file.rs @@ -51,7 +51,7 @@ impl OpenFile { } if let Some(path) = dirpath { ChangeDirectory::cd(path.as_path(), context)?; - LoadChild::load_child(context, backend); + LoadChild::load_child(context)?; } else if let Some(paths) = filepaths { let options = Self::get_options(paths[0]); if options.len() > 0 { diff --git a/src/commands/parent_directory.rs b/src/commands/parent_directory.rs index d7de010..6f654e9 100644 --- a/src/commands/parent_directory.rs +++ b/src/commands/parent_directory.rs @@ -14,10 +14,7 @@ impl ParentDirectory { "parent_directory" } - pub fn parent_directory( - context: &mut JoshutoContext, - backend: &mut TuiBackend, - ) -> std::io::Result<()> { + pub fn parent_directory(context: &mut JoshutoContext) -> std::io::Result<()> { let curr_tab = &mut context.tabs[context.curr_tab_index]; if !curr_tab.curr_path.pop() { return Ok(()); @@ -36,8 +33,8 @@ impl std::fmt::Display for ParentDirectory { } impl JoshutoRunnable for ParentDirectory { - fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { - Self::parent_directory(context, backend)?; + fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { + Self::parent_directory(context)?; Ok(()) } } diff --git a/src/commands/reload_dir.rs b/src/commands/reload_dir.rs index 20d415b..7103970 100644 --- a/src/commands/reload_dir.rs +++ b/src/commands/reload_dir.rs @@ -1,9 +1,6 @@ -use std::collections::hash_map::Entry; - use crate::commands::{JoshutoCommand, JoshutoRunnable}; use crate::context::JoshutoContext; use crate::error::JoshutoResult; -use crate::fs::JoshutoDirList; use crate::ui::TuiBackend; #[derive(Clone, Debug)] @@ -35,7 +32,7 @@ impl std::fmt::Display for ReloadDirList { } impl JoshutoRunnable for ReloadDirList { - fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { + fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { Self::reload(context.curr_tab_index, context)?; Ok(()) } diff --git a/src/commands/rename_file.rs b/src/commands/rename_file.rs index fd43e6d..ad2441c 100644 --- a/src/commands/rename_file.rs +++ b/src/commands/rename_file.rs @@ -58,7 +58,6 @@ impl JoshutoRunnable for RenameFile { if let Some(path) = path { self.rename_file(&path, context, backend)?; - ncurses::doupdate(); } Ok(()) } @@ -113,7 +112,6 @@ impl JoshutoRunnable for RenameFileAppend { if let Some(file_name) = file_name { self.rename_file(context, backend, file_name)?; - ncurses::doupdate(); } Ok(()) } @@ -161,7 +159,6 @@ impl JoshutoRunnable for RenameFilePrepend { if let Some(file_name) = file_name { self.rename_file(context, backend, file_name)?; - ncurses::doupdate(); } Ok(()) } diff --git a/src/commands/search.rs b/src/commands/search.rs index d1101bc..0b7ef76 100644 --- a/src/commands/search.rs +++ b/src/commands/search.rs @@ -66,10 +66,10 @@ impl std::fmt::Display for Search { } impl JoshutoRunnable for Search { - fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { + fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { let index = Self::search(&context.tabs[context.curr_tab_index], &self.pattern); if let Some(index) = index { - cursor_move::cursor_move(index, context, backend); + cursor_move::cursor_move(index, context); } let mut data = SEARCH_PATTERN.lock().unwrap(); match data.as_ref() { @@ -80,23 +80,20 @@ impl JoshutoRunnable for Search { } None => *data = Some(self.pattern.clone()), } - ncurses::doupdate(); Ok(()) } } fn search_with_func( context: &mut JoshutoContext, - backend: &mut TuiBackend, search_func: fn(&JoshutoTab, &str) -> Option<usize>, ) { let data = SEARCH_PATTERN.lock().unwrap(); if let Some(s) = (*data).as_ref() { let index = search_func(&context.tabs[context.curr_tab_index], s); if let Some(index) = index { - cursor_move::cursor_move(index, context, backend); + cursor_move::cursor_move(index, context); } - ncurses::doupdate(); } } @@ -121,8 +118,8 @@ impl std::fmt::Display for SearchNext { } impl JoshutoRunnable for SearchNext { - fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { - search_with_func(context, backend, Search::search); + fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { + search_with_func(context, Search::search); Ok(()) } } @@ -148,8 +145,8 @@ impl std::fmt::Display for SearchPrev { } impl JoshutoRunnable for SearchPrev { - fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { - search_with_func(context, backend, Search::search_rev); + fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { + search_with_func(context, Search::search_rev); Ok(()) } } |