summaryrefslogtreecommitdiffstats
path: root/src/run.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/run.rs')
-rw-r--r--src/run.rs35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/run.rs b/src/run.rs
index 6f3234c..b6b03c8 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -1,12 +1,14 @@
use std::thread;
-use crate::commands::{CommandKeybind, CursorMoveUp, JoshutoRunnable};
+use crate::commands::{CommandKeybind, CursorMoveStub, JoshutoRunnable};
use crate::config::{JoshutoCommandMapping, JoshutoConfig};
use crate::context::JoshutoContext;
use crate::tab::JoshutoTab;
use crate::ui;
use crate::ui::widgets::{TuiCommandMenu, TuiView};
use crate::util::event::Event;
+use crate::history::DirectoryHistory;
+use crate::io::IOWorkerObserver;
pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) -> std::io::Result<()> {
let mut backend: ui::TuiBackend = ui::TuiBackend::new()?;
@@ -20,31 +22,23 @@ pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) -> std::io:
context.push_tab(tab);
// move the cursor by 0 just to trigger a preview of child
- let tmp = CursorMoveUp::new(0);
- tmp.execute(&mut context, &mut backend);
+ CursorMoveStub::new().execute(&mut context, &mut backend);
// render our view
let mut view = TuiView::new(&context);
backend.render(&mut view);
}
- let mut io_handle = None;
+ let mut io_observer = None;
while !context.exit {
/* checking if there are workers that need to be run */
if !context.worker_queue.is_empty() {
- if let None = io_handle.as_ref() {
+ if let None = io_observer.as_ref() {
let worker = context.worker_queue.pop_front().unwrap();
- io_handle = {
+ io_observer = {
let event_tx = context.events.event_tx.clone();
- let thread = thread::spawn(move || {
- worker.start();
- while let Ok(evt) = worker.recv() {
- let _ = event_tx.send(evt);
- }
- worker.handle.join();
- let _ = event_tx.send(Event::IOWorkerResult);
- });
- Some(thread)
+ let observer = IOWorkerObserver::new(worker, event_tx);
+ Some(observer)
};
}
}
@@ -56,16 +50,23 @@ pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) -> std::io:
context.worker_msg = Some(format!("bytes copied {}", p));
}
Event::IOWorkerResult => {
- match io_handle {
+ match io_observer {
Some(handle) => {
+ let src = handle.src.clone();
+ let dest = handle.dest.clone();
handle.join();
context
.message_queue
.push_back("io_worker done".to_string());
+ let options = &context.config_t.sort_option;
+ for tab in context.tabs.iter_mut() {
+ tab.history.create_or_update(src.as_path(), options);
+ tab.history.create_or_update(dest.as_path(), options);
+ }
}
None => {}
}
- io_handle = None;
+ io_observer = None;
context.worker_msg = None;
}
Event::Input(key) => {