aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKunal Mohan <kunalmohan99@gmail.com>2021-05-21 01:32:58 +0530
committerKunal Mohan <kunalmohan99@gmail.com>2021-05-22 22:19:50 +0530
commitb8acf190710e97092def6ef3adfe44e992ca140c (patch)
treec8adb9732b6230481e899955b9cdd694770bdca2
parentAdd ability to detach a session (diff)
downloadsl0ppij-b8acf190710e97092def6ef3adfe44e992ca140c.tar.gz
sl0ppij-b8acf190710e97092def6ef3adfe44e992ca140c.tar.xz
sl0ppij-b8acf190710e97092def6ef3adfe44e992ca140c.zip
Use Action enum for Quit and detach instead of separate messages under ClientToServerMsg
-rw-r--r--zellij-client/src/input_handler.rs4
-rw-r--r--zellij-client/src/lib.rs6
-rw-r--r--zellij-server/src/lib.rs2
-rw-r--r--zellij-server/src/route.rs26
-rw-r--r--zellij-utils/src/input/actions.rs2
-rw-r--r--zellij-utils/src/ipc.rs2
6 files changed, 26 insertions, 16 deletions
diff --git a/zellij-client/src/input_handler.rs b/zellij-client/src/input_handler.rs
index 4e2cff94..9fa001cd 100644
--- a/zellij-client/src/input_handler.rs
+++ b/zellij-client/src/input_handler.rs
@@ -132,7 +132,9 @@ impl InputHandler {
let mut should_break = false;
match action {
- Action::Quit => {
+ Action::Quit | Action::Detach => {
+ self.os_input
+ .send_to_server(ClientToServerMsg::Action(action));
self.exit();
should_break = true;
}
diff --git a/zellij-client/src/lib.rs b/zellij-client/src/lib.rs
index 8f192c38..0eff09af 100644
--- a/zellij-client/src/lib.rs
+++ b/zellij-client/src/lib.rs
@@ -19,8 +19,7 @@ use zellij_utils::{
channels::{SenderType, SenderWithContext, SyncChannelWithContext},
consts::{SESSION_NAME, ZELLIJ_IPC_PIPE},
errors::{ClientContext, ContextType, ErrorInstruction},
- input::config::Config,
- input::options::Options,
+ input::{actions::Action, config::Config, options::Options},
ipc::{ClientAttributes, ClientToServerMsg, ServerToClientMsg},
};
@@ -226,7 +225,7 @@ pub fn start_client(mut os_input: Box<dyn ClientOsApi>, opts: CliArgs, config: C
match client_instruction {
ClientInstruction::Exit => break,
ClientInstruction::Error(backtrace) => {
- let _ = os_input.send_to_server(ClientToServerMsg::ClientExit);
+ let _ = os_input.send_to_server(ClientToServerMsg::Action(Action::Quit));
handle_error(backtrace);
}
ClientInstruction::ServerError(backtrace) => {
@@ -248,7 +247,6 @@ pub fn start_client(mut os_input: Box<dyn ClientOsApi>, opts: CliArgs, config: C
}
}
- let _ = os_input.send_to_server(ClientToServerMsg::ClientExit);
router_thread.join().unwrap();
// cleanup();
diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs
index a52ba9f4..586bd3e6 100644
--- a/zellij-server/src/lib.rs
+++ b/zellij-server/src/lib.rs
@@ -49,11 +49,9 @@ pub(crate) enum ServerInstruction {
impl From<ClientToServerMsg> for ServerInstruction {
fn from(instruction: ClientToServerMsg) -> Self {
match instruction {
- ClientToServerMsg::ClientExit => ServerInstruction::ClientExit,
ClientToServerMsg::NewClient(pos, opts, options) => {
ServerInstruction::NewClient(pos, opts, options)
}
- ClientToServerMsg::DetachSession => ServerInstruction::DetachSession,
_ => unreachable!(),
}
}
diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs
index 408e1e1e..6804fdf7 100644
--- a/zellij-server/src/route.rs
+++ b/zellij-server/src/route.rs
@@ -15,7 +15,13 @@ use zellij_utils::{
ipc::ClientToServerMsg,
};
-fn route_action(action: Action, session: &SessionMetaData, os_input: &dyn ServerOsApi) {
+fn route_action(
+ action: Action,
+ session: &SessionMetaData,
+ os_input: &dyn ServerOsApi,
+ to_server: &SenderWithContext<ServerInstruction>,
+) -> bool {
+ let mut should_break = false;
match action {
Action::Write(val) => {
session
@@ -182,9 +188,17 @@ fn route_action(action: Action, session: &SessionMetaData, os_input: &dyn Server
.send_to_screen(ScreenInstruction::UpdateTabName(c))
.unwrap();
}
+ Action::Quit => {
+ to_server.send(ServerInstruction::ClientExit).unwrap();
+ should_break = true;
+ }
+ Action::Detach => {
+ to_server.send(ServerInstruction::DetachSession).unwrap();
+ should_break = true;
+ }
Action::NoOp => {}
- Action::Quit => panic!("Received unexpected action"),
}
+ should_break
}
pub(crate) fn route_thread_main(
@@ -197,13 +211,11 @@ pub(crate) fn route_thread_main(
err_ctx.update_thread_ctx();
let rlocked_sessions = session_data.read().unwrap();
match instruction {
- ClientToServerMsg::ClientExit | ClientToServerMsg::DetachSession => {
- to_server.send(instruction.into()).unwrap();
- break;
- }
ClientToServerMsg::Action(action) => {
if let Some(rlocked_sessions) = rlocked_sessions.as_ref() {
- route_action(action, rlocked_sessions, &*os_input);
+ if route_action(action, rlocked_sessions, &*os_input, &to_server) {
+ break;
+ }
}
}
ClientToServerMsg::TerminalResize(new_size) => {
diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs
index 5ad771da..4e0ce0cb 100644
--- a/zellij-utils/src/input/actions.rs
+++ b/zellij-utils/src/input/actions.rs
@@ -65,4 +65,6 @@ pub enum Action {
CloseTab,
GoToTab(u32),
TabNameInput(Vec<u8>),
+ /// Detach session and exit
+ Detach,
}
diff --git a/zellij-utils/src/ipc.rs b/zellij-utils/src/ipc.rs
index 6e40fe1f..23b9ff61 100644
--- a/zellij-utils/src/ipc.rs
+++ b/zellij-utils/src/ipc.rs
@@ -54,11 +54,9 @@ pub enum ClientToServerMsg {
DetachSession(SessionId),
// Disconnect from the session we're connected to
DisconnectFromSession,*/
- ClientExit,
TerminalResize(PositionAndSize),
NewClient(ClientAttributes, Box<CliArgs>, Box<Options>),
Action(Action),
- DetachSession,
}
// Types of messages sent from the server to the client