summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/event.rs105
-rw-r--r--src/util/input.rs2
-rw-r--r--src/util/load_child.rs31
-rw-r--r--src/util/mod.rs2
4 files changed, 1 insertions, 139 deletions
diff --git a/src/util/event.rs b/src/util/event.rs
deleted file mode 100644
index c6656ee..0000000
--- a/src/util/event.rs
+++ /dev/null
@@ -1,105 +0,0 @@
-use std::io;
-use std::sync::mpsc;
-use std::thread;
-
-use signal_hook::consts::signal;
-use signal_hook::iterator::exfiltrator::SignalOnly;
-use signal_hook::iterator::SignalsInfo;
-
-use termion::event::Event;
-use termion::input::TermRead;
-
-use crate::io::IoWorkerProgress;
-
-#[derive(Debug)]
-pub enum AppEvent {
- Termion(Event),
- IoWorkerProgress(IoWorkerProgress),
- IoWorkerResult(io::Result<IoWorkerProgress>),
- Signal(i32),
- // Filesystem(notify::Result),
-}
-
-#[derive(Debug, Clone, Copy)]
-pub struct Config {}
-
-impl Default for Config {
- fn default() -> Config {
- Config {}
- }
-}
-
-/// A small event handler that wrap termion input and tick events. Each event
-/// type is handled in its own thread and returned to a common `Receiver`
-pub struct Events {
- pub event_tx: mpsc::Sender<AppEvent>,
- event_rx: mpsc::Receiver<AppEvent>,
- pub input_tx: mpsc::SyncSender<()>,
-}
-
-impl Events {
- pub fn new() -> Self {
- Events::with_config()
- }
-
- pub fn with_config() -> Self {
- let (input_tx, input_rx) = mpsc::sync_channel(1);
- let (event_tx, event_rx) = mpsc::channel();
-
- // signal thread
- let event_tx2 = event_tx.clone();
- let _ = thread::spawn(move || {
- let sigs = vec![signal::SIGWINCH];
- let mut signals = SignalsInfo::<SignalOnly>::new(&sigs).unwrap();
- for signal in &mut signals {
- if let Err(e) = event_tx2.send(AppEvent::Signal(signal)) {
- eprintln!("Signal thread send err: {:#?}", e);
- return;
- }
- }
- });
-
- // input thread
- let event_tx2 = event_tx.clone();
- let _ = thread::spawn(move || {
- let stdin = io::stdin();
- let mut events = stdin.events();
- match events.next() {
- Some(event) => match event {
- Ok(event) => {
- if let Err(e) = event_tx2.send(AppEvent::Termion(event)) {
- eprintln!("Input thread send err: {:#?}", e);
- return;
- }
- }
- Err(_) => return,
- },
- None => return,
- }
-
- while input_rx.recv().is_ok() {
- if let Some(Ok(event)) = events.next() {
- if let Err(e) = event_tx2.send(AppEvent::Termion(event)) {
- eprintln!("Input thread send err: {:#?}", e);
- return;
- }
- }
- }
- });
-
- Events {
- event_tx,
- event_rx,
- input_tx,
- }
- }
-
- pub fn next(&self) -> Result<AppEvent, mpsc::RecvError> {
- let event = self.event_rx.recv()?;
- Ok(event)
- }
-
- pub fn flush(&self) {
- let _ = self.input_tx.send(());
- }
-}
diff --git a/src/util/input.rs b/src/util/input.rs
index 7a6d9ad..24aff5e 100644
--- a/src/util/input.rs
+++ b/src/util/input.rs
@@ -4,10 +4,10 @@ use tui::layout::{Constraint, Direction, Layout};
use crate::commands::{cursor_move, parent_cursor_move, AppExecute, KeyCommand};
use crate::context::AppContext;
+use crate::event::AppEvent;
use crate::history::DirectoryHistory;
use crate::io::{FileOp, IoWorkerProgress};
use crate::ui;
-use crate::util::event::AppEvent;
use crate::util::format;
pub fn process_mouse(event: MouseEvent, context: &mut AppContext, backend: &mut ui::TuiBackend) {
diff --git a/src/util/load_child.rs b/src/util/load_child.rs
deleted file mode 100644
index 63fb1f2..0000000
--- a/src/util/load_child.rs
+++ /dev/null
@@ -1,31 +0,0 @@
-use std::path::PathBuf;
-
-use crate::context::AppContext;
-use crate::history::DirectoryHistory;
-
-pub struct LoadChild {}
-
-impl LoadChild {
- pub fn load_child(context: &mut AppContext) -> std::io::Result<()> {
- let mut path: Option<PathBuf> = None;
- if let Some(curr_list) = context.tab_context_ref().curr_tab_ref().curr_list_ref() {
- if let Some(index) = curr_list.index {
- let entry = &curr_list.contents[index];
- path = Some(entry.file_path().to_path_buf())
- }
- }
-
- // get preview
- if let Some(path) = path {
- if path.is_dir() {
- let options = context.config_ref().display_options_ref().clone();
- context
- .tab_context_mut()
- .curr_tab_mut()
- .history_mut()
- .create_or_soft_update(path.as_path(), &options)?;
- }
- }
- Ok(())
- }
-}
diff --git a/src/util/mod.rs b/src/util/mod.rs
index 53b5512..848ae31 100644
--- a/src/util/mod.rs
+++ b/src/util/mod.rs
@@ -2,10 +2,8 @@
pub mod devicons;
pub mod display;
-pub mod event;
pub mod format;
pub mod input;
-pub mod load_child;
pub mod name_resolution;
pub mod search;
pub mod select;