summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2024-01-05 13:26:08 +0100
committerSebastian Thiel <sebastian.thiel@icloud.com>2024-01-05 13:38:29 +0100
commit0651cae13b43104402ed9d90147ee8c63fe83b61 (patch)
tree1eb30a8dffaa5ae2a34547ccf85efca107d86ad0 /src
parent983ba6172604b83c2e4efad0f03273206a43c5db (diff)
refactor
Diffstat (limited to 'src')
-rw-r--r--src/interactive/app/eventloop.rs2
-rw-r--r--src/interactive/app/input.rs4
-rw-r--r--src/traverse.rs50
3 files changed, 29 insertions, 27 deletions
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, ());
}