summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Zhao <jeff.no.zhao@gmail.com>2021-12-16 19:59:39 -0500
committerJeff Zhao <jeff.no.zhao@gmail.com>2021-12-16 19:59:39 -0500
commit51c567a620e64ed1876df87d7837ba66a4c3e27f (patch)
treed99a27ae1782aa3a8c0b043614eaa8a77d2f5f42
parentae77a0fa7594dcf1a61954d0b0e2de7aac6961ce (diff)
change vec to hashset
-rw-r--r--Cargo.lock24
-rw-r--r--Cargo.toml2
-rw-r--r--src/commands/change_directory.rs3
-rw-r--r--src/commands/cursor_move.rs14
-rw-r--r--src/commands/numbered_command.rs2
-rw-r--r--src/commands/parent_cursor_move.rs7
-rw-r--r--src/commands/parent_directory.rs2
-rw-r--r--src/commands/preview_cursor_move.rs2
-rw-r--r--src/commands/search.rs4
-rw-r--r--src/commands/search_fzf.rs2
-rw-r--r--src/commands/search_glob.rs2
-rw-r--r--src/commands/search_string.rs2
-rw-r--r--src/context/app_context.rs22
-rw-r--r--src/run.rs1
-rw-r--r--src/util/input.rs4
15 files changed, 45 insertions, 48 deletions
diff --git a/Cargo.lock b/Cargo.lock
index ee2c1b7..af9585d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -395,9 +395,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
-version = "0.2.108"
+version = "0.2.112"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
+checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125"
[[package]]
name = "log"
@@ -519,9 +519,9 @@ checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd"
[[package]]
name = "phf"
-version = "0.10.0"
+version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b9fc3db1018c4b59d7d582a739436478b6035138b6aecbce989fc91c3e98409f"
+checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259"
dependencies = [
"phf_macros",
"phf_shared",
@@ -599,9 +599,9 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
[[package]]
name = "proc-macro2"
-version = "1.0.32"
+version = "1.0.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43"
+checksum = "2f84e92c0f7c9d58328b85a78557813e4bd845130db68d7184635344399423b1"
dependencies = [
"unicode-xid",
]
@@ -757,15 +757,15 @@ dependencies = [
[[package]]
name = "serde"
-version = "1.0.130"
+version = "1.0.132"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913"
+checksum = "8b9875c23cf305cd1fd7eb77234cbb705f21ea6a72c637a5c6db5fe4b8e7f008"
[[package]]
name = "serde_derive"
-version = "1.0.130"
+version = "1.0.132"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b"
+checksum = "ecc0db5cb2556c0e558887d9bbdcf6ac4471e83ff66cf696e5419024d1606276"
dependencies = [
"proc-macro2",
"quote",
@@ -789,9 +789,9 @@ dependencies = [
[[package]]
name = "signal-hook"
-version = "0.3.10"
+version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9c98891d737e271a2954825ef19e46bd16bdb98e2746f2eec4f7a4ef7946efd1"
+checksum = "c35dfd12afb7828318348b8c408383cf5071a086c1d4ab1c0f9840ec92dbb922"
dependencies = [
"libc",
"signal-hook-registry",
diff --git a/Cargo.toml b/Cargo.toml
index abc0738..abcf47e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -35,7 +35,7 @@ xdg = "^2"
phf = { version = "^0", features = ["macros"], optional = true }
trash = { version = "^1", optional = true }
unicode-segmentation = "^1"
-ansi-to-tui = "0.4.1"
+ansi-to-tui = "^0"
notify = "5.0.0-pre.13"
[features]
diff --git a/src/commands/change_directory.rs b/src/commands/change_directory.rs
index 4cca418..7b89726 100644
--- a/src/commands/change_directory.rs
+++ b/src/commands/change_directory.rs
@@ -10,7 +10,7 @@ pub fn cd(path: &path::Path, context: &mut AppContext) -> std::io::Result<()> {
Ok(())
}
-pub fn change_directory_helper(path: &path::Path, context: &mut AppContext) -> std::io::Result<()> {
+fn change_directory_helper(path: &path::Path, context: &mut AppContext) -> std::io::Result<()> {
cd(path, context)?;
let options = context.config_ref().display_options_ref().clone();
context
@@ -18,7 +18,6 @@ pub fn change_directory_helper(path: &path::Path, context: &mut AppContext) -> s
.curr_tab_mut()
.history_mut()
.populate_to_root(path, &options)?;
-
Ok(())
}
diff --git a/src/commands/cursor_move.rs b/src/commands/cursor_move.rs
index 3303abb..def90b2 100644
--- a/src/commands/cursor_move.rs
+++ b/src/commands/cursor_move.rs
@@ -38,7 +38,7 @@ pub fn lazy_load_directory_size(context: &mut AppContext) {
}
}
-pub fn cursor_move(new_index: usize, context: &mut AppContext) {
+pub fn cursor_move(context: &mut AppContext, new_index: usize) {
lazy_load_directory_size(context);
let mut new_index = new_index;
if let Some(curr_list) = context.tab_context_mut().curr_tab_mut().curr_list_mut() {
@@ -59,7 +59,7 @@ pub fn up(context: &mut AppContext, u: usize) -> JoshutoResult<()> {
};
if let Some(s) = movement {
- cursor_move(s, context);
+ cursor_move(context, s);
}
Ok(())
}
@@ -70,7 +70,7 @@ pub fn down(context: &mut AppContext, u: usize) -> JoshutoResult<()> {
None => None,
};
if let Some(s) = movement {
- cursor_move(s, context);
+ cursor_move(context, s);
}
Ok(())
}
@@ -89,7 +89,7 @@ pub fn home(context: &mut AppContext) -> JoshutoResult<()> {
};
if let Some(s) = movement {
- cursor_move(s, context);
+ cursor_move(context, s);
}
Ok(())
}
@@ -108,7 +108,7 @@ pub fn end(context: &mut AppContext) -> JoshutoResult<()> {
};
if let Some(s) = movement {
- cursor_move(s, context);
+ cursor_move(context, s);
}
Ok(())
}
@@ -142,7 +142,7 @@ pub fn page_up(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoRes
};
if let Some(s) = movement {
- cursor_move(s, context);
+ cursor_move(context, s);
}
Ok(())
}
@@ -165,7 +165,7 @@ pub fn page_down(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoR
};
if let Some(s) = movement {
- cursor_move(s, context);
+ cursor_move(context, s);
}
Ok(())
}
diff --git a/src/commands/numbered_command.rs b/src/commands/numbered_command.rs
index 0926364..39775e6 100644
--- a/src/commands/numbered_command.rs
+++ b/src/commands/numbered_command.rs
@@ -45,7 +45,7 @@ pub fn numbered_command(
match event {
Event::Key(Key::Esc) => return Ok(()),
Event::Key(Key::Char('g')) => {
- cursor_move::cursor_move(num_prefix - 1, context);
+ cursor_move::cursor_move(context, num_prefix - 1);
return Ok(());
}
Event::Key(Key::Char(c)) if c.is_numeric() => {
diff --git a/src/commands/parent_cursor_move.rs b/src/commands/parent_cursor_move.rs
index 7743b3f..d1247d1 100644
--- a/src/commands/parent_cursor_move.rs
+++ b/src/commands/parent_cursor_move.rs
@@ -3,7 +3,7 @@ use std::path::PathBuf;
use crate::context::AppContext;
use crate::error::JoshutoResult;
-pub fn parent_cursor_move(new_index: usize, context: &mut AppContext) -> JoshutoResult<()> {
+pub fn parent_cursor_move(context: &mut AppContext, new_index: usize) -> JoshutoResult<()> {
let mut path: Option<PathBuf> = None;
let mut new_index = new_index;
@@ -36,8 +36,9 @@ pub fn parent_up(context: &mut AppContext, u: usize) -> JoshutoResult<()> {
};
if let Some(s) = movement {
- parent_cursor_move(s, context)?;
+ parent_cursor_move(context, s)?;
}
+ context.update_watcher();
Ok(())
}
@@ -47,7 +48,7 @@ pub fn parent_down(context: &mut AppContext, u: usize) -> JoshutoResult<()> {
None => None,
};
if let Some(s) = movement {
- parent_cursor_move(s, context)?;
+ parent_cursor_move(context, s)?;
}
Ok(())
}
diff --git a/src/commands/parent_directory.rs b/src/commands/parent_directory.rs
index 02eecbf..1fc1bb0 100644
--- a/src/commands/parent_directory.rs
+++ b/src/commands/parent_directory.rs
@@ -2,7 +2,7 @@ use crate::commands::reload;
use crate::context::AppContext;
use crate::error::JoshutoResult;
-pub fn parent_directory_helper(context: &mut AppContext) -> std::io::Result<()> {
+fn parent_directory_helper(context: &mut AppContext) -> std::io::Result<()> {
if let Some(parent) = context
.tab_context_ref()
.curr_tab_ref()
diff --git a/src/commands/preview_cursor_move.rs b/src/commands/preview_cursor_move.rs
index 7ce434b..c9c7238 100644
--- a/src/commands/preview_cursor_move.rs
+++ b/src/commands/preview_cursor_move.rs
@@ -3,7 +3,7 @@ use std::path::PathBuf;
use crate::context::AppContext;
use crate::error::JoshutoResult;
-pub fn preview_cursor_move(context: &mut AppContext, new_index: usize) -> JoshutoResult<()> {
+fn preview_cursor_move(context: &mut AppContext, new_index: usize) -> JoshutoResult<()> {
let file_path: Option<PathBuf> = {
let curr_tab = context.tab_context_ref().curr_tab_ref();
let curr_list = curr_tab.curr_list_ref();
diff --git a/src/commands/search.rs b/src/commands/search.rs
index d3a43f1..81cfd79 100644
--- a/src/commands/search.rs
+++ b/src/commands/search.rs
@@ -17,7 +17,7 @@ pub fn search_next(context: &mut AppContext) -> JoshutoResult<()> {
}
};
if let Some(index) = index {
- let _ = cursor_move::cursor_move(index, context);
+ let _ = cursor_move::cursor_move(context, index);
}
}
Ok(())
@@ -34,7 +34,7 @@ pub fn search_prev(context: &mut AppContext) -> JoshutoResult<()> {
}
};
if let Some(index) = index {
- let _ = cursor_move::cursor_move(index, context);
+ let _ = cursor_move::cursor_move(context, index);
}
}
Ok(())
diff --git a/src/commands/search_fzf.rs b/src/commands/search_fzf.rs
index a551f7f..6512cf4 100644
--- a/src/commands/search_fzf.rs
+++ b/src/commands/search_fzf.rs
@@ -55,7 +55,7 @@ pub fn search_fzf(context: &mut AppContext, backend: &mut TuiBackend) -> Joshuto
let selected_idx_str = selected.split_once(' ');
if let Some((selected_idx_str, _)) = selected_idx_str {
if let Ok(index) = selected_idx_str.parse::<usize>() {
- cursor_move::cursor_move(index, context);
+ let _ = cursor_move::cursor_move(context, index);
}
}
}
diff --git a/src/commands/search_glob.rs b/src/commands/search_glob.rs
index 62c0949..a6ca267 100644
--- a/src/commands/search_glob.rs
+++ b/src/commands/search_glob.rs
@@ -42,7 +42,7 @@ pub fn search_glob(context: &mut AppContext, pattern: &str) -> JoshutoResult<()>
let index = search_glob_fwd(context.tab_context_ref().curr_tab_ref(), &glob);
if let Some(index) = index {
- let _ = cursor_move::cursor_move(index, context);
+ let _ = cursor_move::cursor_move(context, index);
}
context.set_search_context(SearchPattern::Glob(glob));
Ok(())
diff --git a/src/commands/search_string.rs b/src/commands/search_string.rs
index 15cb5ce..b5ea94a 100644
--- a/src/commands/search_string.rs
+++ b/src/commands/search_string.rs
@@ -40,7 +40,7 @@ pub fn search_string(context: &mut AppContext, pattern: &str) -> JoshutoResult<(
let pattern = pattern.to_lowercase();
let index = search_string_fwd(context.tab_context_ref().curr_tab_ref(), pattern.as_str());
if let Some(index) = index {
- let _ = cursor_move::cursor_move(index, context);
+ let _ = cursor_move::cursor_move(context, index);
}
context.set_search_context(SearchPattern::String(pattern));
Ok(())
diff --git a/src/context/app_context.rs b/src/context/app_context.rs
index 07620b3..30aafae 100644
--- a/src/context/app_context.rs
+++ b/src/context/app_context.rs
@@ -1,3 +1,4 @@
+use std::collections::HashSet;
use std::sync::mpsc;
use crate::config;
@@ -49,7 +50,7 @@ pub struct AppContext {
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
watcher: notify::NullWatcher,
// list of watched paths; seems not to be possible to get them from a notify::Watcher
- watched_paths: Vec<path::PathBuf>,
+ watched_paths: HashSet<path::PathBuf>,
}
impl AppContext {
@@ -68,7 +69,7 @@ impl AppContext {
Err(_) => {}
})
.unwrap();
- let watched_paths: Vec<path::PathBuf> = Vec::with_capacity(3);
+ let watched_paths = HashSet::with_capacity(3);
Self {
quit: QuitType::DoNot,
@@ -89,35 +90,32 @@ impl AppContext {
pub fn update_watcher(&mut self) {
// collect the paths that shall be watched...
- let mut new_paths_to_watch: Vec<path::PathBuf> = Vec::with_capacity(3);
+ let mut new_paths_to_watch: HashSet<path::PathBuf> = HashSet::with_capacity(3);
if let Some(dir_list) = self.tab_context_ref().curr_tab_ref().curr_list_ref() {
- new_paths_to_watch.push(dir_list.file_path().to_path_buf())
+ new_paths_to_watch.insert(dir_list.file_path().to_path_buf());
}
if let Some(dir_list) = self.tab_context_ref().curr_tab_ref().parent_list_ref() {
- new_paths_to_watch.push(dir_list.file_path().to_path_buf())
+ new_paths_to_watch.insert(dir_list.file_path().to_path_buf());
}
if let Some(dir_list) = self.tab_context_ref().curr_tab_ref().child_list_ref() {
- new_paths_to_watch.push(dir_list.file_path().to_path_buf())
+ new_paths_to_watch.insert(dir_list.file_path().to_path_buf());
}
// remove paths from watcher which don't need to be watched anymore...
for old_watched_path in &self.watched_paths {
- if !new_paths_to_watch.contains(&old_watched_path) {
+ if !new_paths_to_watch.contains(old_watched_path.as_path()) {
let _ = self.watcher.unwatch(old_watched_path.as_path());
}
}
// add paths to watcher which need to be watched...
for new_watched_path in &new_paths_to_watch {
- if !self.watched_paths.contains(&new_watched_path) {
+ if !self.watched_paths.contains(new_watched_path.as_path()) {
let _ = self
.watcher
.watch(new_watched_path.as_path(), RecursiveMode::NonRecursive);
}
}
// update own list of watched paths
- self.watched_paths.clear();
- for new_watched_path in new_paths_to_watch {
- self.watched_paths.push(new_watched_path);
- }
+ self.watched_paths = new_paths_to_watch;
}
// event related
diff --git a/src/run.rs b/src/run.rs
index f249625..4063c35 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -86,6 +86,5 @@ pub fn run(
}
context.update_watcher();
}
-
Ok(())
}
diff --git a/src/util/input.rs b/src/util/input.rs
index 137e30d..90ac118 100644
--- a/src/util/input.rs
+++ b/src/util/input.rs
@@ -241,11 +241,11 @@ pub fn process_mouse(
dirlist.first_index_for_viewport(layout_rect[1].height as usize);
let new_index = skip_dist + (y - layout_rect[1].y - 1) as usize;
if is_parent {
- if let Err(e) = parent_cursor_move::parent_cursor_move(new_index, context) {
+ if let Err(e) = parent_cursor_move::parent_cursor_move(context, new_index) {
context.message_queue_mut().push_error(e.to_string());
}
} else {
- cursor_move::cursor_move(new_index, context);
+ cursor_move::cursor_move(context, new_index);
}
}
} else {