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 <mail@beyermatthias.de>

* 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 <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2022-07-12 12:17:24 +02:00 committed by GitHub
parent ee6a9cd78e
commit 6e102c6084
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 5 deletions

View file

@ -189,6 +189,7 @@ impl InputHandler {
} }
} }
fn handle_actions(&mut self, actions: Vec<Action>, session_name: &str, clients: Vec<ClientId>) { fn handle_actions(&mut self, actions: Vec<Action>, session_name: &str, clients: Vec<ClientId>) {
let mut detached = false;
for action in actions { for action in actions {
match action { match action {
Action::Quit => { Action::Quit => {
@ -200,6 +201,7 @@ impl InputHandler {
let last = clients.last().unwrap(); let last = clients.last().unwrap();
self.os_input self.os_input
.send_to_server(ClientToServerMsg::DetachSession(vec![*first, *last])); .send_to_server(ClientToServerMsg::DetachSession(vec![*first, *last]));
detached = true;
break; break;
}, },
// Actions, that are independent from the specific client // Actions, that are independent from the specific client
@ -238,7 +240,11 @@ impl InputHandler {
self.dispatch_action(Action::Detach, None); self.dispatch_action(Action::Detach, None);
self.should_exit = true; self.should_exit = true;
log::error!("Quitting Now. Dispatched the actions"); log::error!("Quitting Now. Dispatched the actions");
self.exit(); if detached {
self.exit(ExitReason::NormalDetached);
} else {
self.exit(ExitReason::Normal);
}
} }
/// Dispatches an [`Action`]. /// Dispatches an [`Action`].
@ -257,10 +263,16 @@ impl InputHandler {
match action { match action {
Action::NoOp => {}, Action::NoOp => {},
Action::Quit | Action::Detach => { Action::Quit => {
self.os_input self.os_input
.send_to_server(ClientToServerMsg::Action(action, client_id)); .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; should_break = true;
}, },
Action::SwitchToMode(mode) => { Action::SwitchToMode(mode) => {
@ -298,9 +310,9 @@ impl InputHandler {
/// Routine to be called when the input handler exits (at the moment this is the /// Routine to be called when the input handler exits (at the moment this is the
/// same as quitting Zellij). /// same as quitting Zellij).
fn exit(&mut self) { fn exit(&mut self, reason: ExitReason) {
self.send_client_instructions self.send_client_instructions
.send(ClientInstruction::Exit(ExitReason::Normal)) .send(ClientInstruction::Exit(reason))
.unwrap(); .unwrap();
} }
} }

View file

@ -113,6 +113,7 @@ pub enum ServerToClientMsg {
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
pub enum ExitReason { pub enum ExitReason {
Normal, Normal,
NormalDetached,
ForceDetached, ForceDetached,
CannotAttach, CannotAttach,
Error(String), Error(String),
@ -122,6 +123,7 @@ impl Display for ExitReason {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
match self { match self {
Self::Normal => write!(f, "Bye from Zellij!"), Self::Normal => write!(f, "Bye from Zellij!"),
Self::NormalDetached => write!(f, "Session detached"),
Self::ForceDetached => write!( Self::ForceDetached => write!(
f, f,
"Session was detached from this client (possibly because another client connected)" "Session was detached from this client (possibly because another client connected)"