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)"