diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/actioner.rs | 19 | ||||
-rw-r--r-- | src/help.rs | 1 | ||||
-rw-r--r-- | src/lib.rs | 1 | ||||
-rw-r--r-- | src/log.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 49 | ||||
-rw-r--r-- | src/status.rs | 3 | ||||
-rw-r--r-- | src/utils.rs | 48 |
7 files changed, 52 insertions, 71 deletions
diff --git a/src/actioner.rs b/src/actioner.rs index 259f09d..0c0a33c 100644 --- a/src/actioner.rs +++ b/src/actioner.rs @@ -71,9 +71,6 @@ impl Actioner { Event::Key(Key::Ctrl('q')) => self.escape(status), Event::Key(Key::Delete) => self.delete(status), Event::Key(Key::Insert) => self.insert(status), - Event::Key(Key::Alt('q')) => self.alt_q(status), - Event::Key(Key::Alt('d')) => self.alt_d(status), - Event::Key(Key::Char('Q')) => self.shift_q(status), Event::Key(Key::Char(c)) => self.char(status, c), Event::Key(Key::Home) => self.home(status), Event::Key(Key::End) => self.end(status), @@ -362,22 +359,6 @@ impl Actioner { status.selected().event_decompress() } - fn shift_q(&self, status: &mut Status) -> FmResult<()> { - status.selected().event_quit(); - Ok(()) - } - - fn alt_q(&self, status: &mut Status) -> FmResult<()> { - status.print_path_on_quit = true; - status.selected().event_quit(); - Ok(()) - } - - fn alt_d(&self, status: &mut Status) -> FmResult<()> { - status.selected().event_drag_n_drop()?; - Ok(()) - } - /// Match read key to a relevent event, depending on keybindings. /// Keybindings are read from `Config`. fn char(&self, status: &mut Status, c: char) -> FmResult<()> { diff --git a/src/help.rs b/src/help.rs index df71ea4..dd2cea9 100644 --- a/src/help.rs +++ b/src/help.rs @@ -4,7 +4,6 @@ pub static HELP_LINES: &str = " Default key bindings: q: quit -Atl+q: quit and print selected path h: help - Navigation - @@ -25,4 +25,5 @@ pub mod skim; pub mod status; pub mod tab; pub mod term_manager; +pub mod utils; pub mod visited; @@ -41,7 +41,7 @@ pub fn set_logger() -> FmResult<Handle> { CompoundPolicy::new(Box::new(size_trigger), Box::new(fixed_window_roller)); let log_path = shellexpand::tilde(LOG_PATH).to_string(); // Don't propagate the error with ? since it crashes the application. - create_log_folder(LOG_PATH)?; + create_log_folder(&log_path)?; // Log Trace level output to file where trace is the default level // and the programmatically specified level to stderr. let config = Config::builder() diff --git a/src/main.rs b/src/main.rs index c0d82b4..90f04e3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,64 +2,19 @@ use std::sync::Arc; use clap::Parser; use log::info; -use sysinfo::{Disk, DiskExt, System, SystemExt}; -use tuikit::term::Term; +use sysinfo::{System, SystemExt}; use fm::actioner::Actioner; use fm::args::Args; use fm::config::load_config; -use fm::fileinfo::human_size; use fm::fm_error::FmResult; use fm::log::set_logger; use fm::status::Status; use fm::term_manager::{Display, EventReader}; +use fm::utils::{disk_space, init_term, print_on_quit}; static CONFIG_PATH: &str = "~/.config/fm/config.yaml"; -/// Returns a `Display` instance after `tuikit::term::Term` creation. -fn init_term() -> FmResult<Term> { - let term: Term<()> = Term::new()?; - term.enable_mouse_support()?; - Ok(term) -} - -fn disk_space(disks: &[Disk], path_str: String) -> String { - if path_str.is_empty() { - return "".to_owned(); - } - let mut size = 0_u64; - let mut disks: Vec<&Disk> = disks.iter().collect(); - disks.sort_by_key(|disk| disk.mount_point().as_os_str().len()); - for disk in disks { - if path_str.contains(disk.mount_point().as_os_str().to_str().unwrap()) { - size = disk.available_space(); - }; - } - human_size(size) -} - -fn print_on_quit( - term: Arc<Term>, - actioner: Actioner, - event_reader: EventReader, - status: Status, - display: Display, -) { - if status.print_path_on_quit { - let path = status - .selected_non_mut() - .path_content - .selected_path_str() - .unwrap_or_default(); - std::mem::drop(term); - std::mem::drop(actioner); - std::mem::drop(event_reader); - std::mem::drop(status); - std::mem::drop(display); - println!("{}", path) - } -} - /// Main function /// Init the status and display and listen to events from keyboard and mouse. /// The application is redrawn after every event. diff --git a/src/status.rs b/src/status.rs index b553028..9bd14ee 100644 --- a/src/status.rs +++ b/src/status.rs @@ -39,8 +39,6 @@ pub struct Status { pub marks: Marks, /// Colors for extension pub colors: ColorCache, - /// Should it display the last selected file before exiting? - pub print_path_on_quit: bool, /// terminal term: Arc<Term>, } @@ -57,7 +55,6 @@ impl Status { jump_index: 0, marks: Marks::read_from_config_file(), colors: ColorCache::default(), - print_path_on_quit: false, term, }) } diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..3ce6685 --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,48 @@ +use std::sync::Arc; + +use sysinfo::{Disk, DiskExt}; +use tuikit::term::Term; + +use crate::actioner::Actioner; +use crate::fileinfo::human_size; +use crate::fm_error::FmResult; +use crate::status::Status; +use crate::term_manager::{Display, EventReader}; + +/// Returns a `Display` instance after `tuikit::term::Term` creation. +pub fn init_term() -> FmResult<Term> { + let term: Term<()> = Term::new()?; + term.enable_mouse_support()?; + Ok(term) +} + +pub fn disk_space(disks: &[Disk], path_str: String) -> String { + if path_str.is_empty() { + return "".to_owned(); + } + let mut size = 0_u64; + let mut disks: Vec<&Disk> = disks.iter().collect(); + disks.sort_by_key(|disk| disk.mount_point().as_os_str().len()); + for disk in disks { + if path_str.contains(disk.mount_point().as_os_str().to_str().unwrap()) { + size = disk.available_space(); + }; + } + human_size(size) +} + +pub fn print_on_quit( + term: Arc<Term>, + actioner: Actioner, + event_reader: EventReader, + status: Status, + display: Display, +) { + let path = status.selected_non_mut().path_str().unwrap_or_default(); + std::mem::drop(term); + std::mem::drop(actioner); + std::mem::drop(event_reader); + std::mem::drop(status); + std::mem::drop(display); + println!("{}", path) +} |