Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0651cae

Browse files
committed
refactor
1 parent 983ba61 commit 0651cae

5 files changed

Lines changed: 30 additions & 30 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ include = ["src/**/*", "Cargo.*", "LICENSE", "README.md", "CHANGELOG.md", "!**/t
1111

1212
[features]
1313
default = ["tui-crossplatform", "trash-move"]
14-
tui-crossplatform = ["crosstermion/tui-react-crossterm", "crossterm", "tui", "tui-react", "open", "unicode-segmentation", "unicode-width"]
14+
tui-crossplatform = ["crosstermion/tui-react-crossterm", "tui", "tui-react", "open", "unicode-segmentation", "unicode-width"]
1515

1616
trash-move = ["trash"]
1717

@@ -32,7 +32,6 @@ chrono = { version = "0.4.31", default-features = false, features = ["std"] }
3232
unicode-segmentation = { version = "1.3.0", optional = true }
3333
unicode-width = { version = "0.1.5", optional = true }
3434
crosstermion = { version = "0.13.0", default-features = false, optional = true }
35-
crossterm = { version = "0.27", optional = true }
3635
tui = { package = "ratatui", version = "0.25.0", optional = true, default-features = false }
3736
tui-react = { version = "0.22.0", optional = true }
3837
open = { version = "5.0", optional = true }

src/interactive/app/eventloop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ impl TerminalApp {
437437

438438
let mut events = fetch_buffered_key_events(&keys_rx);
439439
if let Some(event) = event {
440-
// Updater is triggered by an event, insert it
440+
// This update is triggered by a user event, insert it
441441
// before any events fetched later.
442442
events.insert(0, event);
443443
}

src/interactive/app/input.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crossbeam::channel::Receiver;
2-
pub use crossterm::event::Event;
2+
pub use crosstermion::crossterm::event::Event;
33

44
enum Action<T> {
55
Continue,
@@ -18,7 +18,7 @@ pub fn input_channel() -> Receiver<Event> {
1818
let (key_send, key_receive) = crossbeam::channel::bounded(0);
1919
std::thread::spawn(move || -> Result<(), std::io::Error> {
2020
loop {
21-
let event = match continue_on_interrupt(crossterm::event::read()) {
21+
let event = match continue_on_interrupt(crosstermion::crossterm::event::read()) {
2222
Action::Continue => continue,
2323
Action::Result(res) => res?,
2424
};

src/traverse.rs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -152,31 +152,33 @@ impl Traversal {
152152
}
153153

154154
let (entry_tx, entry_rx) = crossbeam::channel::bounded(100);
155-
let walk_options_clone = walk_options.clone();
156155
std::thread::Builder::new()
157156
.name("dua-fs-walk-dispatcher".to_string())
158-
.spawn(move || {
159-
for path in input.into_iter() {
160-
let device_id = match crossdev::init(path.as_ref()) {
161-
Ok(id) => id,
162-
Err(_) => {
163-
t.io_errors += 1;
164-
continue;
165-
}
166-
};
167-
let shared_path = Arc::new(path);
157+
.spawn({
158+
let walk_options = walk_options.clone();
159+
move || {
160+
for root_path in input.into_iter() {
161+
let device_id = match crossdev::init(root_path.as_ref()) {
162+
Ok(id) => id,
163+
Err(_) => {
164+
t.io_errors += 1;
165+
continue;
166+
}
167+
};
168168

169-
for entry in walk_options_clone
170-
.iter_from_path(shared_path.as_ref(), device_id)
171-
.into_iter()
172-
{
173-
if entry_tx
174-
.send((entry, Arc::clone(&shared_path), device_id))
175-
.is_err()
169+
let root_path = Arc::new(root_path);
170+
for entry in walk_options
171+
.iter_from_path(root_path.as_ref(), device_id)
172+
.into_iter()
176173
{
177-
// The channel is closed, this means the user has
178-
// requested to quit the app. Abort the walking.
179-
return;
174+
if entry_tx
175+
.send((entry, Arc::clone(&root_path), device_id))
176+
.is_err()
177+
{
178+
// The channel is closed, this means the user has
179+
// requested to quit the app. Abort the walking.
180+
return;
181+
}
180182
}
181183
}
182184
}
@@ -185,7 +187,7 @@ impl Traversal {
185187
loop {
186188
crossbeam::select! {
187189
recv(entry_rx) -> entry => {
188-
let Ok((entry, path, device_id)) = entry else {
190+
let Ok((entry, root_path, device_id)) = entry else {
189191
break;
190192
};
191193

@@ -194,7 +196,7 @@ impl Traversal {
194196
match entry {
195197
Ok(entry) => {
196198
data.name = if entry.depth < 1 {
197-
(*path).clone()
199+
(*root_path).clone()
198200
} else {
199201
entry.file_name.into()
200202
};
@@ -289,7 +291,7 @@ impl Traversal {
289291
}
290292
Err(_) => {
291293
if previous_depth == 0 {
292-
data.name = (*path).clone();
294+
data.name = (*root_path).clone();
293295
let entry_index = t.tree.add_node(data);
294296
t.tree.add_edge(parent_node_idx, entry_index, ());
295297
}

0 commit comments

Comments
 (0)