Add more quit options

Adds the following messages.

- PrintPwdAndQuit
- PrintFocusPathAndQuit
- PrintSelectionAndQuit

Closed: https://github.com/sayanarijit/xplr/issues/257
pull/260/head
Arijit Basu 3 years ago committed by Arijit Basu
parent 6a70b568bf
commit 6b03598b5d

@ -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> {
self.msg_out.push_back(MsgOut::PrintPwdAndQuit);
Ok(self)
}
fn print_focus_path_and_quit(mut self) -> Result<Self> {
self.msg_out.push_back(MsgOut::PrintFocusPathAndQuit);
Ok(self)
}
fn print_selection_and_quit(mut self) -> Result<Self> {
self.msg_out.push_back(MsgOut::PrintSelectionAndQuit);
Ok(self)
}
fn print_result_and_quit(mut self) -> Result<Self> {
self.msg_out.push_back(MsgOut::PrintResultAndQuit);
Ok(self)

@ -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;

Loading…
Cancel
Save