diff --git a/src/app.rs b/src/app.rs index 5f06d45..9023f84 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1306,7 +1306,16 @@ pub enum ExternalMsg { /// Quit with returncode zero (success). Quit, - /// Print selected paths if it's not empty, else, print the focused node's path. + /// Print $PWD and quit. + PrintPwdAndQuit, + + /// Print the path under focus and quit. It can be empty string if there's nothing to focus. + PrintFocusPathAndQuit, + + /// Print the selected paths and quit. It can be empty is no path is selected. + PrintSelectionAndQuit, + + /// Print the selected paths if it's not empty, else, print the focused node's path. PrintResultAndQuit, /// Print the state of application in YAML format. Helpful for debugging or generating @@ -1363,8 +1372,6 @@ pub enum MsgOut { Refresh, ClearScreen, Quit, - PrintResultAndQuit, - PrintAppStateAndQuit, Debug(String), Call(Command), CallSilently(Command), @@ -1377,6 +1384,11 @@ pub enum MsgOut { StartFifo(String), StopFifo, ToggleFifo(String), + PrintPwdAndQuit, + PrintFocusPathAndQuit, + PrintSelectionAndQuit, + PrintResultAndQuit, + PrintAppStateAndQuit, } #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] @@ -1744,6 +1756,9 @@ impl App { ExternalMsg::LogWarning(l) => self.log_warning(l), ExternalMsg::LogError(l) => self.log_error(l), ExternalMsg::Quit => self.quit(), + ExternalMsg::PrintPwdAndQuit => self.print_pwd_and_quit(), + ExternalMsg::PrintFocusPathAndQuit => self.print_focus_path_and_quit(), + ExternalMsg::PrintSelectionAndQuit => self.print_selection_and_quit(), ExternalMsg::PrintResultAndQuit => self.print_result_and_quit(), ExternalMsg::PrintAppStateAndQuit => self.print_app_state_and_quit(), ExternalMsg::Debug(path) => self.debug(path), @@ -2517,6 +2532,21 @@ impl App { Ok(self) } + fn print_pwd_and_quit(mut self) -> Result { + self.msg_out.push_back(MsgOut::PrintPwdAndQuit); + Ok(self) + } + + fn print_focus_path_and_quit(mut self) -> Result { + self.msg_out.push_back(MsgOut::PrintFocusPathAndQuit); + Ok(self) + } + + fn print_selection_and_quit(mut self) -> Result { + self.msg_out.push_back(MsgOut::PrintSelectionAndQuit); + Ok(self) + } + fn print_result_and_quit(mut self) -> Result { self.msg_out.push_back(MsgOut::PrintResultAndQuit); Ok(self) diff --git a/src/runner.rs b/src/runner.rs index d091ac3..404536a 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -211,6 +211,23 @@ impl Runner { break 'outer; } + app::MsgOut::PrintPwdAndQuit => { + result = Ok(Some(format!("{}\n", app.pwd()))); + break 'outer; + } + + app::MsgOut::PrintFocusPathAndQuit => { + result = Ok(app + .focused_node() + .map(|n| format!("{}\n", n.absolute_path()))); + break 'outer; + } + + app::MsgOut::PrintSelectionAndQuit => { + result = Ok(Some(app.selection_str())); + break 'outer; + } + app::MsgOut::PrintResultAndQuit => { result = Ok(Some(app.result_str())); break 'outer;