From 6e102c60842b4bda3fb11934968fddfa8de9eae5 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 12 Jul 2022 12:17:24 +0200 Subject: [PATCH] fix(cli): let the exit message be different when detaching (#1573) * Let the exit message be different when detaching This patch changes the exit message printed to the user, so the user does not get the impression that they fat-fingered an "exit" instead of what was intended (a detach). For this, the InputHandler::exit() function was refactored, to get the reason as a parameter. As this function is not pub, this is considered okay. Signed-off-by: Matthias Beyer * Change detach message This patch changes the detach message to be more in line with the other messages zellij displays to the user. Signed-off-by: Matthias Beyer --- zellij-client/src/input_handler.rs | 22 +++++++++++++++++----- zellij-utils/src/ipc.rs | 2 ++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/zellij-client/src/input_handler.rs b/zellij-client/src/input_handler.rs index 5f8cc063..7428bac0 100644 --- a/zellij-client/src/input_handler.rs +++ b/zellij-client/src/input_handler.rs @@ -189,6 +189,7 @@ impl InputHandler { } } fn handle_actions(&mut self, actions: Vec, session_name: &str, clients: Vec) { + let mut detached = false; for action in actions { match action { Action::Quit => { @@ -200,6 +201,7 @@ impl InputHandler { let last = clients.last().unwrap(); self.os_input .send_to_server(ClientToServerMsg::DetachSession(vec![*first, *last])); + detached = true; break; }, // Actions, that are independent from the specific client @@ -238,7 +240,11 @@ impl InputHandler { self.dispatch_action(Action::Detach, None); self.should_exit = true; log::error!("Quitting Now. Dispatched the actions"); - self.exit(); + if detached { + self.exit(ExitReason::NormalDetached); + } else { + self.exit(ExitReason::Normal); + } } /// Dispatches an [`Action`]. @@ -257,10 +263,16 @@ impl InputHandler { match action { Action::NoOp => {}, - Action::Quit | Action::Detach => { + Action::Quit => { self.os_input .send_to_server(ClientToServerMsg::Action(action, client_id)); - self.exit(); + self.exit(ExitReason::Normal); + should_break = true; + }, + Action::Detach => { + self.os_input + .send_to_server(ClientToServerMsg::Action(action, client_id)); + self.exit(ExitReason::NormalDetached); should_break = true; }, Action::SwitchToMode(mode) => { @@ -298,9 +310,9 @@ impl InputHandler { /// Routine to be called when the input handler exits (at the moment this is the /// same as quitting Zellij). - fn exit(&mut self) { + fn exit(&mut self, reason: ExitReason) { self.send_client_instructions - .send(ClientInstruction::Exit(ExitReason::Normal)) + .send(ClientInstruction::Exit(reason)) .unwrap(); } } diff --git a/zellij-utils/src/ipc.rs b/zellij-utils/src/ipc.rs index db9dd039..a5268979 100644 --- a/zellij-utils/src/ipc.rs +++ b/zellij-utils/src/ipc.rs @@ -113,6 +113,7 @@ pub enum ServerToClientMsg { #[derive(Serialize, Deserialize, Debug, Clone)] pub enum ExitReason { Normal, + NormalDetached, ForceDetached, CannotAttach, Error(String), @@ -122,6 +123,7 @@ impl Display for ExitReason { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { match self { Self::Normal => write!(f, "Bye from Zellij!"), + Self::NormalDetached => write!(f, "Session detached"), Self::ForceDetached => write!( f, "Session was detached from this client (possibly because another client connected)"