diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2022-04-22 16:53:04 -0400 |
---|---|---|
committer | Jeff Zhao <jeff.no.zhao@gmail.com> | 2022-04-22 16:53:04 -0400 |
commit | 9cc4f10fdb3e31723289892be5929ccd0a1c48d7 (patch) | |
tree | 29fed413a9236b546b477a521e21eb6c9d2bf3f4 /src/commands | |
parent | 763815418ac3acd56aa7e936c48861ae6e73ca40 (diff) |
combine --output-dir and --choosefiles into a single argument
--output-file is used for all output by joshuto
and can be specified what to output by:
`quit --output-current-directory`
`quit --output-selected-files`
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/open_file.rs | 5 | ||||
-rw-r--r-- | src/commands/quit.rs | 44 | ||||
-rw-r--r-- | src/commands/tab_ops.rs | 4 |
3 files changed, 29 insertions, 24 deletions
diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs index bf89627..48c0d0b 100644 --- a/src/commands/open_file.rs +++ b/src/commands/open_file.rs @@ -3,7 +3,7 @@ use std::path; use crate::commands::reload; use crate::config::AppMimetypeEntry; -use crate::context::{AppContext, QuitType}; +use crate::context::AppContext; use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult}; use crate::ui::views::TuiTextField; use crate::ui::TuiBackend; @@ -35,9 +35,6 @@ pub fn open(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult change_directory::cd(path.as_path(), context)?; reload::soft_reload(context.tab_context_ref().index, context)?; } - Some(_) if context.args.choosefiles.is_some() => { - context.quit = QuitType::ChooseFiles; - } Some(_) => { let paths = curr_list.map_or_else(Vec::new, |s| s.get_selected_paths()); let path = paths.get(0).ok_or_else(|| { diff --git a/src/commands/quit.rs b/src/commands/quit.rs index 0d3d31a..ccc9a8b 100644 --- a/src/commands/quit.rs +++ b/src/commands/quit.rs @@ -1,22 +1,35 @@ use std::io; -use crate::context::{AppContext, QuitType}; +use crate::context::AppContext; use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult}; -pub fn quit(context: &mut AppContext) -> JoshutoResult { - let worker_context = context.worker_context_ref(); - if worker_context.is_busy() || !worker_context.is_empty() { - Err(JoshutoError::new( - JoshutoErrorKind::Io(io::ErrorKind::Other), - String::from("operations running in background, use force_quit to quit"), - )) - } else { - context.quit = QuitType::Normal; - Ok(()) +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum QuitAction { + DoNot, + Noop, + Force, + OutputCurrentDirectory, + OutputSelectedFiles, +} + +impl QuitAction { + pub const fn exit_code(&self) -> i32 { + match *self { + Self::Noop => 0, + Self::DoNot => 10, + Self::Force => 100, + Self::OutputCurrentDirectory => 101, + Self::OutputSelectedFiles => 102, + } } } -pub fn quit_to_current_directory(context: &mut AppContext) -> JoshutoResult { +pub fn quit_with_action(context: &mut AppContext, quit_action: QuitAction) -> JoshutoResult { + if quit_action == QuitAction::Force { + context.quit = quit_action; + return Ok(()); + } + let worker_context = context.worker_context_ref(); if worker_context.is_busy() || !worker_context.is_empty() { Err(JoshutoError::new( @@ -24,12 +37,7 @@ pub fn quit_to_current_directory(context: &mut AppContext) -> JoshutoResult { String::from("operations running in background, use force_quit to quit"), )) } else { - context.quit = QuitType::ToCurrentDirectory; + context.quit = quit_action; Ok(()) } } - -pub fn force_quit(context: &mut AppContext) -> JoshutoResult { - context.quit = QuitType::Force; - Ok(()) -} diff --git a/src/commands/tab_ops.rs b/src/commands/tab_ops.rs index ef87e7a..32bfeb1 100644 --- a/src/commands/tab_ops.rs +++ b/src/commands/tab_ops.rs @@ -7,7 +7,7 @@ use crate::tab::{JoshutoTab, TabHomePage}; use crate::HOME_DIR; -use super::quit; +use super::quit::{quit_with_action, QuitAction}; fn _tab_switch(new_index: usize, context: &mut AppContext) -> std::io::Result<()> { context.tab_context_mut().index = new_index; @@ -110,7 +110,7 @@ pub fn new_tab(context: &mut AppContext) -> JoshutoResult { pub fn close_tab(context: &mut AppContext) -> JoshutoResult { if context.tab_context_ref().len() <= 1 { - return quit::quit(context); + return quit_with_action(context, QuitAction::Noop); } let mut tab_index = context.tab_context_ref().index; |