Skip to content

Commit

Permalink
Allow deletion of files while scanning, it should yield IOerrors only…
Browse files Browse the repository at this point in the history
…; improve 'scanning' message
  • Loading branch information
Byron committed Mar 29, 2020
1 parent 5f2bc2d commit 8c3294e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/interactive/app/eventloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct AppState {
pub message: Option<String>,
pub focussed: FocussedPane,
pub bookmarks: BTreeMap<TreeIndex, TreeIndex>,
pub is_scanning: bool,
}

impl AppState {
Expand Down Expand Up @@ -72,6 +73,7 @@ impl AppState {

self.draw(window, traversal, display.clone(), terminal)?;
for key in keys.filter_map(Result::ok) {
self.reset_message();
match key {
Char('?') => self.toggle_help_pane(window),
Char('\t') => {
Expand Down Expand Up @@ -190,7 +192,7 @@ impl TerminalApp {
})),
}

let fetch_buffered_key_events = || {
let fetch_buffered_key_events = move || {
let mut keys = Vec::new();
while let Ok(key) = keys_rx.try_recv() {
keys.push(key);
Expand All @@ -208,8 +210,8 @@ impl TerminalApp {
AppState {
root: traversal.root_index,
sorting,
message: Some("-> scanning <-".into()),
entries: sorted_entries(&traversal.tree, traversal.root_index, sorting),
is_scanning: true,
..Default::default()
}
});
Expand All @@ -225,6 +227,7 @@ impl TerminalApp {
)?;
Ok(())
})?;
drop(fetch_buffered_key_events); // shutdown input event handler early for good measure

display.byte_vis = ByteVisualization::PercentageAndBar;
Ok(TerminalApp {
Expand All @@ -240,7 +243,7 @@ impl TerminalApp {
..Default::default()
}
});
s.reset_message();
s.is_scanning = false;
s.entries = sorted_entries(&traversal.tree, s.root, s.sorting);
s.selected = s.selected.or_else(|| s.entries.get(0).map(|b| b.index));
s
Expand Down
6 changes: 5 additions & 1 deletion src/interactive/app/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ impl AppState {
}

pub fn reset_message(&mut self) {
self.message = None;
if self.is_scanning {
self.message = Some("-> scanning <-".into());
} else {
self.message = None;
}
}

pub fn toggle_help_pane(&mut self, window: &mut MainWindow) {
Expand Down
5 changes: 5 additions & 0 deletions src/interactive/app_test/journeys_readonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ fn simple_user_journey_read_only() -> Result<(), Error> {
"it will sort entries in descending order by size"
);

assert_eq!(
app.state.is_scanning, false,
"it will not think it is still scanning"
);

let first_selected_path = OsString::from(format!("{}/{}", FIXTURE_PATH, long_root));
assert_eq!(
node_by_name(&app, &first_selected_path).name,
Expand Down

0 comments on commit 8c3294e

Please sign in to comment.