diff options
Diffstat (limited to 'src/interactive/app/terminal_app.rs')
-rw-r--r-- | src/interactive/app/terminal_app.rs | 63 |
1 files changed, 5 insertions, 58 deletions
diff --git a/src/interactive/app/terminal_app.rs b/src/interactive/app/terminal_app.rs index 537cb6f..5d57cf1 100644 --- a/src/interactive/app/terminal_app.rs +++ b/src/interactive/app/terminal_app.rs @@ -13,7 +13,7 @@ use tui_react::Terminal; use crate::{crossdev, interactive::widgets::MainWindow}; use super::{ - app_state::{AppState, ProcessingResult, TraversalState}, + app_state::{AppState, ProcessingResult}, sorted_entries, DisplayOptions, }; @@ -26,14 +26,6 @@ pub struct TerminalApp { pub walk_options: WalkOptions, } -pub type TraversalEntry = - Result<jwalk::DirEntry<((), Option<Result<std::fs::Metadata, jwalk::Error>>)>, jwalk::Error>; - -pub enum TraversalEvent { - Entry(TraversalEntry, Arc<PathBuf>, u64), - Finished(u64), -} - impl TerminalApp { pub fn initialize<B>( terminal: &mut Terminal<B>, @@ -87,59 +79,16 @@ impl TerminalApp { Ok(app) } - pub fn scan(&mut self, input: Vec<PathBuf>) -> Result<Receiver<TraversalEvent>> { - self.state.traversal_state = TraversalState::new(self.traversal.root_index); - self.state.is_scanning = true; - - let (entry_tx, entry_rx) = crossbeam::channel::bounded(100); - std::thread::Builder::new() - .name("dua-fs-walk-dispatcher".to_string()) - .spawn({ - let walk_options = self.walk_options.clone(); - let mut io_errors: u64 = 0; - move || { - for root_path in input.into_iter() { - let device_id = match crossdev::init(root_path.as_ref()) { - Ok(id) => id, - Err(_) => { - io_errors += 1; - continue; - } - }; - - let root_path = Arc::new(root_path); - for entry in walk_options - .iter_from_path(root_path.as_ref(), device_id) - .into_iter() - { - if entry_tx - .send(TraversalEvent::Entry( - 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; - } - } - } - if entry_tx.send(TraversalEvent::Finished(io_errors)).is_err() { - log::error!("Failed to send TraversalEvents::Finished event"); - } - } - })?; - - Ok(entry_rx) + pub fn traverse(&mut self, input: Vec<PathBuf>) -> Result<()> { + self.state + .traverse(&self.traversal, &self.walk_options, input)?; + Ok(()) } pub fn process_events<B>( &mut self, terminal: &mut Terminal<B>, events: Receiver<Event>, - traversal: Receiver<TraversalEvent>, ) -> Result<WalkResult> where B: Backend, @@ -149,9 +98,7 @@ impl TerminalApp { &mut self.traversal, &mut self.display, terminal, - &self.walk_options, events, - traversal, )? { ProcessingResult::ExitRequested(res) => Ok(res), } |