diff options
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/bulk_rename.rs | 4 | ||||
-rw-r--r-- | src/commands/command_line.rs | 4 | ||||
-rw-r--r-- | src/commands/cursor_move.rs | 14 | ||||
-rw-r--r-- | src/commands/delete_files.rs | 8 | ||||
-rw-r--r-- | src/commands/numbered_command.rs | 4 | ||||
-rw-r--r-- | src/commands/open_file.rs | 140 | ||||
-rw-r--r-- | src/commands/rename_file.rs | 10 | ||||
-rw-r--r-- | src/commands/search_fzf.rs | 4 | ||||
-rw-r--r-- | src/commands/set_mode.rs | 4 | ||||
-rw-r--r-- | src/commands/show_help.rs | 4 | ||||
-rw-r--r-- | src/commands/show_tasks.rs | 4 | ||||
-rw-r--r-- | src/commands/sub_process.rs | 4 | ||||
-rw-r--r-- | src/commands/subdir_fzf.rs | 4 | ||||
-rw-r--r-- | src/commands/zoxide.rs | 4 |
14 files changed, 106 insertions, 106 deletions
diff --git a/src/commands/bulk_rename.rs b/src/commands/bulk_rename.rs index 540036b..3a94f11 100644 --- a/src/commands/bulk_rename.rs +++ b/src/commands/bulk_rename.rs @@ -8,7 +8,7 @@ use rand::Rng; use crate::context::AppContext; use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult}; -use crate::ui::TuiBackend; +use crate::ui::AppBackend; use crate::util::process::wait_for_enter; use super::reload; @@ -122,7 +122,7 @@ pub fn _bulk_rename(context: &mut AppContext) -> JoshutoResult { Ok(()) } -pub fn bulk_rename(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult { +pub fn bulk_rename(context: &mut AppContext, backend: &mut AppBackend) -> JoshutoResult { context.remove_external_preview(); backend.terminal_drop(); let res = _bulk_rename(context); diff --git a/src/commands/command_line.rs b/src/commands/command_line.rs index 887ea32..9c5aa70 100644 --- a/src/commands/command_line.rs +++ b/src/commands/command_line.rs @@ -5,11 +5,11 @@ use crate::context::AppContext; use crate::error::JoshutoResult; use crate::key_command::{AppExecute, Command}; use crate::ui::views::TuiTextField; -use crate::ui::TuiBackend; +use crate::ui::AppBackend; pub fn read_and_execute( context: &mut AppContext, - backend: &mut TuiBackend, + backend: &mut AppBackend, keymap_t: &AppKeyMapping, prefix: &str, suffix: &str, diff --git a/src/commands/cursor_move.rs b/src/commands/cursor_move.rs index 64809c5..ccb8d98 100644 --- a/src/commands/cursor_move.rs +++ b/src/commands/cursor_move.rs @@ -1,6 +1,6 @@ use crate::context::AppContext; use crate::error::JoshutoResult; -use crate::ui::TuiBackend; +use crate::ui::AppBackend; pub fn lazy_load_directory_size(context: &mut AppContext) { let directory_size = match context @@ -120,7 +120,7 @@ pub fn end(context: &mut AppContext) -> JoshutoResult { Ok(()) } -fn get_page_size(context: &AppContext, backend: &TuiBackend) -> Option<usize> { +fn get_page_size(context: &AppContext, backend: &AppBackend) -> Option<usize> { let config = context.config_ref(); let rect = backend.terminal.as_ref().map(|t| t.size())?.ok()?; @@ -140,7 +140,7 @@ fn get_page_size(context: &AppContext, backend: &TuiBackend) -> Option<usize> { pub fn page_up( context: &mut AppContext, - backend: &mut TuiBackend, + backend: &mut AppBackend, proportion: f64, ) -> JoshutoResult { let page_size = get_page_size(context, backend).unwrap_or(10) as f64 * proportion; @@ -160,7 +160,7 @@ pub fn page_up( pub fn page_down( context: &mut AppContext, - backend: &mut TuiBackend, + backend: &mut AppBackend, proportion: f64, ) -> JoshutoResult { let page_size = get_page_size(context, backend).unwrap_or(10) as f64 * proportion; @@ -178,7 +178,7 @@ pub fn page_down( Ok(()) } -pub fn page_home(context: &mut AppContext, _: &mut TuiBackend) -> JoshutoResult { +pub fn page_home(context: &mut AppContext, _: &mut AppBackend) -> JoshutoResult { let new_index = context .tab_context_ref() .curr_tab_ref() @@ -190,7 +190,7 @@ pub fn page_home(context: &mut AppContext, _: &mut TuiBackend) -> JoshutoResult Ok(()) } -pub fn page_middle(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult { +pub fn page_middle(context: &mut AppContext, backend: &mut AppBackend) -> JoshutoResult { let movement = get_page_size(context, backend).unwrap_or(10) / 2; let new_index = context @@ -204,7 +204,7 @@ pub fn page_middle(context: &mut AppContext, backend: &mut TuiBackend) -> Joshut Ok(()) } -pub fn page_end(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult { +pub fn page_end(context: &mut AppContext, backend: &mut AppBackend) -> JoshutoResult { let movement = get_page_size(context, backend).unwrap_or(10) - 1; let new_index = context diff --git a/src/commands/delete_files.rs b/src/commands/delete_files.rs index 126346f..b702771 100644 --- a/src/commands/delete_files.rs +++ b/src/commands/delete_files.rs @@ -6,7 +6,7 @@ use termion::event::Key; use crate::context::AppContext; use crate::history::DirectoryHistory; use crate::ui::widgets::TuiPrompt; -use crate::ui::TuiBackend; +use crate::ui::AppBackend; use super::reload; @@ -50,7 +50,7 @@ where Ok(()) } -fn delete_files(context: &mut AppContext, backend: &mut TuiBackend) -> std::io::Result<()> { +fn delete_files(context: &mut AppContext, backend: &mut AppBackend) -> std::io::Result<()> { let delete_func = if context.config_ref().use_trash { trash_files } else { @@ -79,7 +79,7 @@ fn delete_files(context: &mut AppContext, backend: &mut TuiBackend) -> std::io:: }; match ch { - Key::Char('y') | Key::Char('\n') => { + Key::Char('Y') | Key::Char('y') | Key::Char('\n') => { let confirm_delete = if paths_len > 1 { // prompt user again for deleting multiple files let ch = { @@ -112,7 +112,7 @@ fn delete_files(context: &mut AppContext, backend: &mut TuiBackend) -> std::io:: pub fn delete_selected_files( context: &mut AppContext, - backend: &mut TuiBackend, + backend: &mut AppBackend, ) -> std::io::Result<()> { let _ = delete_files(context, backend)?; diff --git a/src/commands/numbered_command.rs b/src/commands/numbered_command.rs index c35205b..c1331da 100644 --- a/src/commands/numbered_command.rs +++ b/src/commands/numbered_command.rs @@ -8,12 +8,12 @@ use crate::event::process_event; use crate::event::AppEvent; use crate::key_command::{CommandKeybind, NumberedExecute}; use crate::ui::views::TuiView; -use crate::ui::TuiBackend; +use crate::ui::AppBackend; pub fn numbered_command( first_char: char, context: &mut AppContext, - backend: &mut TuiBackend, + backend: &mut AppBackend, keymap: &AppKeyMapping, ) -> JoshutoResult { context.flush_event(); diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs index a2b157e..ad90a91 100644 --- a/src/commands/open_file.rs +++ b/src/commands/open_file.rs @@ -6,14 +6,14 @@ use crate::config::AppMimetypeEntry; use crate::context::AppContext; use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult}; use crate::ui::views::TuiTextField; -use crate::ui::TuiBackend; +use crate::ui::AppBackend; use crate::util::process::{execute_and_wait, fork_execute}; use super::change_directory; use crate::MIMETYPE_T; -pub fn get_options<'a>(path: &path::Path) -> Vec<&'a AppMimetypeEntry> { +fn _get_options<'a>(path: &path::Path) -> Vec<&'a AppMimetypeEntry> { let mut options: Vec<&AppMimetypeEntry> = Vec::new(); if let Some(file_ext) = path.extension() { if let Some(file_ext) = file_ext.to_str() { @@ -24,47 +24,9 @@ pub fn get_options<'a>(path: &path::Path) -> Vec<&'a AppMimetypeEntry> { options } -pub fn open(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult { - let curr_list = context.tab_context_ref().curr_tab_ref().curr_list_ref(); - let entry = curr_list.and_then(|s| s.curr_entry_ref().cloned()); - - match entry { - None => (), - Some(entry) if entry.file_path().is_dir() => { - let path = entry.file_path().to_path_buf(); - change_directory::cd(path.as_path(), context)?; - reload::soft_reload(context.tab_context_ref().index, context)?; - } - Some(entry) => { - let paths = curr_list.map_or_else(Vec::new, |s| s.iter_selected().cloned().collect()); - let (path, files) = if paths.is_empty() { - (entry.file_path(), vec![entry.file_name()]) - } else { - ( - paths.get(0).unwrap().file_path(), - paths.iter().map(|e| e.file_name()).collect(), - ) - }; - let options = get_options(path); - let option = options.iter().find(|option| option.program_exists()); - - let config = context.config_ref(); - - if let Some(option) = option { - open_with_entry(context, backend, option, &files)?; - } else if config.xdg_open { - open_with_xdg(context, backend, path)?; - } else { - open_with_helper(context, backend, options, &files)?; - } - } - } - Ok(()) -} - -pub fn open_with_entry<S>( +fn _open_with_entry<S>( context: &mut AppContext, - backend: &mut TuiBackend, + backend: &mut AppBackend, option: &AppMimetypeEntry, files: &[S], ) -> std::io::Result<()> @@ -82,9 +44,9 @@ where Ok(()) } -pub fn open_with_xdg( +fn _open_with_xdg( context: &mut AppContext, - backend: &mut TuiBackend, + backend: &mut AppBackend, path: &path::Path, ) -> std::io::Result<()> { let config = context.config_ref(); @@ -100,9 +62,9 @@ pub fn open_with_xdg( Ok(()) } -pub fn open_with_helper<S>( +fn _open_with_helper<S>( context: &mut AppContext, - backend: &mut TuiBackend, + backend: &mut AppBackend, options: Vec<&AppMimetypeEntry>, files: &[S], ) -> std::io::Result<()> @@ -139,7 +101,7 @@ where } Ok(n) => { let option = &options[n]; - open_with_entry(context, backend, option, files)?; + _open_with_entry(context, backend, option, files)?; } Err(_) => { let mut args_iter = user_input.split_whitespace(); @@ -159,34 +121,47 @@ where Ok(()) } -pub fn open_with_interactive(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult { - let mut paths = context - .tab_context_ref() - .curr_tab_ref() - .curr_list_ref() - .map_or(vec![], |s| s.iter_selected().cloned().collect()); +pub fn open(context: &mut AppContext, backend: &mut AppBackend) -> JoshutoResult { + let curr_list = context.tab_context_ref().curr_tab_ref().curr_list_ref(); + let entry = curr_list.and_then(|s| s.curr_entry_ref().cloned()); - if paths.is_empty() { - paths.push( - context - .tab_context_ref() - .curr_tab_ref() - .curr_list_ref() - .and_then(|s| s.curr_entry_ref()) - .unwrap() - .clone(), - ); - } - let files: Vec<&str> = paths.iter().map(|e| e.file_name()).collect(); - let options = get_options(paths[0].file_path()); + match entry { + None => (), + Some(entry) if entry.file_path().is_dir() => { + let path = entry.file_path().to_path_buf(); + change_directory::cd(path.as_path(), context)?; + reload::soft_reload(context.tab_context_ref().index, context)?; + } + Some(entry) => { + let paths = curr_list.map_or_else(Vec::new, |s| s.iter_selected().cloned().collect()); + let (path, files) = if paths.is_empty() { + (entry.file_path(), vec![entry.file_name()]) + } else { + ( + paths.get(0).unwrap().file_path(), + paths.iter().map(|e| e.file_name()).collect(), + ) + }; + let options = _get_options(path); + let option = options.iter().find(|option| option.program_exists()); + + let config = context.config_ref(); - open_with_helper(context, backend, options, &files)?; + if let Some(option) = option { + _open_with_entry(context, backend, option, &files)?; + } else if config.xdg_open { + _open_with_xdg(context, backend, path)?; + } else { + _open_with_helper(context, backend, options, &files)?; + } + } + } Ok(()) } pub fn open_with_index( context: &mut AppContext, - backend: &mut TuiBackend, + backend: &mut AppBackend, index: usize, ) -> JoshutoResult { let paths = context @@ -202,7 +177,7 @@ pub fn open_with_index( )); } let files: Vec<&str> = paths.iter().map(|e| e.file_name()).collect(); - let options = get_options(paths[0].file_path()); + let options = _get_options(paths[0].file_path()); if index >= options.len() { return Err(JoshutoError::new( @@ -212,6 +187,31 @@ pub fn open_with_index( } let option = &options[index]; - open_with_entry(context, backend, option, &files)?; + _open_with_entry(context, backend, option, &files)?; + Ok(()) +} + +pub fn open_with_interactive(context: &mut AppContext, backend: &mut AppBackend) -> JoshutoResult { + let mut paths = context + .tab_context_ref() + .curr_tab_ref() + .curr_list_ref() + .map_or(vec![], |s| s.iter_selected().cloned().collect()); + + if paths.is_empty() { + paths.push( + context + .tab_context_ref() + .curr_tab_ref() + .curr_list_ref() + .and_then(|s| s.curr_entry_ref()) + .unwrap() + .clone(), + ); + } + let files: Vec<&str> = paths.iter().map(|e| e.file_name()).collect(); + let options = _get_options(paths[0].file_path()); + + _open_with_helper(context, backend, options, &files)?; Ok(()) } diff --git a/src/commands/rename_file.rs b/src/commands/rename_file.rs index fa4a23d..cce7ab1 100644 --- a/src/commands/rename_file.rs +++ b/src/commands/rename_file.rs @@ -4,7 +4,7 @@ use crate::config::AppKeyMapping; use crate::context::AppContext; use crate::error::JoshutoResult; use crate::history::create_dirlist_with_history; -use crate::ui::TuiBackend; +use crate::ui::AppBackend; use super::command_line; @@ -52,7 +52,7 @@ pub fn rename_file(context: &mut AppContext, dest: &path::Path) -> JoshutoResult pub fn _rename_file_append( context: &mut AppContext, - backend: &mut TuiBackend, + backend: &mut AppBackend, keymap_t: &AppKeyMapping, file_name: &str, ) -> JoshutoResult { @@ -68,7 +68,7 @@ pub fn _rename_file_append( pub fn rename_file_append( context: &mut AppContext, - backend: &mut TuiBackend, + backend: &mut AppBackend, keymap_t: &AppKeyMapping, ) -> JoshutoResult { let mut file_name: Option<String> = None; @@ -87,7 +87,7 @@ pub fn rename_file_append( pub fn _rename_file_prepend( context: &mut AppContext, - backend: &mut TuiBackend, + backend: &mut AppBackend, keymap_t: &AppKeyMapping, file_name: String, ) -> JoshutoResult { @@ -98,7 +98,7 @@ pub fn _rename_file_prepend( pub fn rename_file_prepend( context: &mut AppContext, - backend: &mut TuiBackend, + backend: &mut AppBackend, keymap_t: &AppKeyMapping, ) -> JoshutoResult { let file_name = context diff --git a/src/commands/search_fzf.rs b/src/commands/search_fzf.rs index 0ae9fae..056fd10 100644 --- a/src/commands/search_fzf.rs +++ b/src/commands/search_fzf.rs @@ -5,9 +5,9 @@ use std::process::{Command, Stdio}; use crate::commands::cursor_move; use crate::context::AppContext; use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult}; -use crate::ui::TuiBackend; +use crate::ui::AppBackend; -pub fn search_fzf(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult { +pub fn search_fzf(context: &mut AppContext, backend: &mut AppBackend) -> JoshutoResult { let items = context .tab_context_ref() .curr_tab_ref() diff --git a/src/commands/set_mode.rs b/src/commands/set_mode.rs index 2691483..d62d8a4 100644 --- a/src/commands/set_mode.rs +++ b/src/commands/set_mode.rs @@ -3,7 +3,7 @@ use std::fs; use crate::context::AppContext; use crate::error::JoshutoResult; use crate::ui::views::TuiTextField; -use crate::ui::TuiBackend; +use crate::ui::AppBackend; use crate::util::unix; use super::cursor_move; @@ -35,7 +35,7 @@ pub fn str_to_mode(s: &str) -> u32 { mode } -pub fn set_mode(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult { +pub fn set_mode(context: &mut AppContext, backend: &mut AppBackend) -> JoshutoResult { #[cfg(unix)] use std::os::unix::fs::PermissionsExt; diff --git a/src/commands/show_help.rs b/src/commands/show_help.rs index 739c63b..a8a7a4b 100644 --- a/src/commands/show_help.rs +++ b/src/commands/show_help.rs @@ -10,11 +10,11 @@ use crate::event::AppEvent; use crate::key_command::{Command, CommandKeybind}; use crate::ui::widgets; use crate::ui::widgets::TuiHelp; -use crate::ui::TuiBackend; +use crate::ui::AppBackend; pub fn help_loop( context: &mut AppContext, - backend: &mut TuiBackend, + backend: &mut AppBackend, keymap_t: &AppKeyMapping, ) -> JoshutoResult { context.flush_event(); diff --git a/src/commands/show_tasks.rs b/src/commands/show_tasks.rs index 4b22860..64312a1 100644 --- a/src/commands/show_tasks.rs +++ b/src/commands/show_tasks.rs @@ -5,12 +5,12 @@ use crate::event::process_event; use crate::event::AppEvent; use crate::key_command::{Command, CommandKeybind}; use crate::ui::views::TuiWorkerView; -use crate::ui::TuiBackend; +use crate::ui::AppBackend; use crate::util::to_string::ToString; pub fn show_tasks( context: &mut AppContext, - backend: &mut TuiBackend, + backend: &mut AppBackend, keymap_t: &AppKeyMapping, ) -> JoshutoResult { context.flush_event(); diff --git a/src/commands/sub_process.rs b/src/commands/sub_process.rs index e3e2e5e..e2a33dc 100644 --- a/src/commands/sub_process.rs +++ b/src/commands/sub_process.rs @@ -1,6 +1,6 @@ use crate::context::AppContext; use crate::error::JoshutoResult; -use crate::ui::TuiBackend; +use crate::ui::AppBackend; use std::process::{Command, Stdio}; use super::reload; @@ -49,7 +49,7 @@ fn execute_sub_process( /// Handler for Joshuto's `shell` and `spawn` commands. pub fn sub_process( context: &mut AppContext, - backend: &mut TuiBackend, + backend: &mut AppBackend, words: &[String], spawn: bool, ) -> JoshutoResult { diff --git a/src/commands/subdir_fzf.rs b/src/commands/subdir_fzf.rs index d1adc07..0944915 100644 --- a/src/commands/subdir_fzf.rs +++ b/src/commands/subdir_fzf.rs @@ -5,11 +5,11 @@ use std::process::{Command, Stdio}; use crate::context::AppContext; use crate::error::JoshutoResult; -use crate::ui::TuiBackend; +use crate::ui::AppBackend; use super::change_directory::change_directory; -pub fn subdir_fzf(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult { +pub fn subdir_fzf(context: &mut AppContext, backend: &mut AppBackend) -> JoshutoResult { let fzf_default_command = std::env::var("FZF_DEFAULT_COMMAND")?; backend.terminal_drop(); diff --git a/src/commands/zoxide.rs b/src/commands/zoxide.rs index 9ee1bf6..0725618 100644 --- a/src/commands/zoxide.rs +++ b/src/commands/zoxide.rs @@ -5,7 +5,7 @@ use std::process::{Command, Stdio}; use crate::commands::change_directory; use crate::context::AppContext; use crate::error::JoshutoResult; -use crate::ui::TuiBackend; +use crate::ui::AppBackend; pub fn zoxide_query(context: &mut AppContext, args: &str) -> JoshutoResult { let cwd = std::env::current_dir()?; @@ -39,7 +39,7 @@ pub fn zoxide_query(context: &mut AppContext, args: &str) -> JoshutoResult { pub fn zoxide_query_interactive( context: &mut AppContext, - backend: &mut TuiBackend, + backend: &mut AppBackend, ) -> JoshutoResult { backend.terminal_drop(); |