diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2024-01-05 13:26:08 +0100 |
---|---|---|
committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2024-01-05 13:38:29 +0100 |
commit | 0651cae13b43104402ed9d90147ee8c63fe83b61 (patch) | |
tree | 1eb30a8dffaa5ae2a34547ccf85efca107d86ad0 | |
parent | 983ba6172604b83c2e4efad0f03273206a43c5db (diff) |
refactor
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | src/interactive/app/eventloop.rs | 2 | ||||
-rw-r--r-- | src/interactive/app/input.rs | 4 | ||||
-rw-r--r-- | src/traverse.rs | 50 |
5 files changed, 30 insertions, 30 deletions
@@ -357,7 +357,6 @@ dependencies = [ "chrono", "clap", "crossbeam", - "crossterm", "crosstermion", "filesize", "gix-glob", @@ -11,7 +11,7 @@ include = ["src/**/*", "Cargo.*", "LICENSE", "README.md", "CHANGELOG.md", "!**/t [features] default = ["tui-crossplatform", "trash-move"] -tui-crossplatform = ["crosstermion/tui-react-crossterm", "crossterm", "tui", "tui-react", "open", "unicode-segmentation", "unicode-width"] +tui-crossplatform = ["crosstermion/tui-react-crossterm", "tui", "tui-react", "open", "unicode-segmentation", "unicode-width"] trash-move = ["trash"] @@ -32,7 +32,6 @@ chrono = { version = "0.4.31", default-features = false, features = ["std"] } unicode-segmentation = { version = "1.3.0", optional = true } unicode-width = { version = "0.1.5", optional = true } crosstermion = { version = "0.13.0", default-features = false, optional = true } -crossterm = { version = "0.27", optional = true } tui = { package = "ratatui", version = "0.25.0", optional = true, default-features = false } tui-react = { version = "0.22.0", optional = true } open = { version = "5.0", optional = true } diff --git a/src/interactive/app/eventloop.rs b/src/interactive/app/eventloop.rs index 985d725..cec4506 100644 --- a/src/interactive/app/eventloop.rs +++ b/src/interactive/app/eventloop.rs @@ -437,7 +437,7 @@ impl TerminalApp { let mut events = fetch_buffered_key_events(&keys_rx); if let Some(event) = event { - // Updater is triggered by an event, insert it + // This update is triggered by a user event, insert it // before any events fetched later. events.insert(0, event); } diff --git a/src/interactive/app/input.rs b/src/interactive/app/input.rs index 58dd3d4..3dc1e54 100644 --- a/src/interactive/app/input.rs +++ b/src/interactive/app/input.rs @@ -1,5 +1,5 @@ use crossbeam::channel::Receiver; -pub use crossterm::event::Event; +pub use crosstermion::crossterm::event::Event; enum Action<T> { Continue, @@ -18,7 +18,7 @@ pub fn input_channel() -> Receiver<Event> { let (key_send, key_receive) = crossbeam::channel::bounded(0); std::thread::spawn(move || -> Result<(), std::io::Error> { loop { - let event = match continue_on_interrupt(crossterm::event::read()) { + let event = match continue_on_interrupt(crosstermion::crossterm::event::read()) { Action::Continue => continue, Action::Result(res) => res?, }; diff --git a/src/traverse.rs b/src/traverse.rs index 49958aa..69c1639 100644 --- a/src/traverse.rs +++ b/src/traverse.rs @@ -152,31 +152,33 @@ impl Traversal { } let (entry_tx, entry_rx) = crossbeam::channel::bounded(100); - let walk_options_clone = walk_options.clone(); std::thread::Builder::new() .name("dua-fs-walk-dispatcher".to_string()) - .spawn(move || { - for path in input.into_iter() { - let device_id = match crossdev::init(path.as_ref()) { - Ok(id) => id, - Err(_) => { - t.io_errors += 1; - continue; - } - }; - let shared_path = Arc::new(path); + .spawn({ + let walk_options = walk_options.clone(); + move || { + for root_path in input.into_iter() { + let device_id = match crossdev::init(root_path.as_ref()) { + Ok(id) => id, + Err(_) => { + t.io_errors += 1; + continue; + } + }; - for entry in walk_options_clone - .iter_from_path(shared_path.as_ref(), device_id) - .into_iter() - { - if entry_tx - .send((entry, Arc::clone(&shared_path), device_id)) - .is_err() + let root_path = Arc::new(root_path); + for entry in walk_options + .iter_from_path(root_path.as_ref(), device_id) + .into_iter() { - // The channel is closed, this means the user has - // requested to quit the app. Abort the walking. - return; + if entry_tx + .send((entry, Arc::clone(&root_path), device_id)) + .is_err() + { + // The channel is closed, this means the user has + // requested to quit the app. Abort the walking. + return; + } } } } @@ -185,7 +187,7 @@ impl Traversal { loop { crossbeam::select! { recv(entry_rx) -> entry => { - let Ok((entry, path, device_id)) = entry else { + let Ok((entry, root_path, device_id)) = entry else { break; }; @@ -194,7 +196,7 @@ impl Traversal { match entry { Ok(entry) => { data.name = if entry.depth < 1 { - (*path).clone() + (*root_path).clone() } else { entry.file_name.into() }; @@ -289,7 +291,7 @@ impl Traversal { } Err(_) => { if previous_depth == 0 { - data.name = (*path).clone(); + data.name = (*root_path).clone(); let entry_index = t.tree.add_node(data); t.tree.add_edge(parent_node_idx, entry_index, ()); } |