Use Action enum for Quit and detach instead of separate messages under ClientToServerMsg
This commit is contained in:
parent
61aa104576
commit
b8acf19071
6 changed files with 26 additions and 16 deletions
|
|
@ -132,7 +132,9 @@ impl InputHandler {
|
||||||
let mut should_break = false;
|
let mut should_break = false;
|
||||||
|
|
||||||
match action {
|
match action {
|
||||||
Action::Quit => {
|
Action::Quit | Action::Detach => {
|
||||||
|
self.os_input
|
||||||
|
.send_to_server(ClientToServerMsg::Action(action));
|
||||||
self.exit();
|
self.exit();
|
||||||
should_break = true;
|
should_break = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,7 @@ use zellij_utils::{
|
||||||
channels::{SenderType, SenderWithContext, SyncChannelWithContext},
|
channels::{SenderType, SenderWithContext, SyncChannelWithContext},
|
||||||
consts::{SESSION_NAME, ZELLIJ_IPC_PIPE},
|
consts::{SESSION_NAME, ZELLIJ_IPC_PIPE},
|
||||||
errors::{ClientContext, ContextType, ErrorInstruction},
|
errors::{ClientContext, ContextType, ErrorInstruction},
|
||||||
input::config::Config,
|
input::{actions::Action, config::Config, options::Options},
|
||||||
input::options::Options,
|
|
||||||
ipc::{ClientAttributes, ClientToServerMsg, ServerToClientMsg},
|
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 {
|
match client_instruction {
|
||||||
ClientInstruction::Exit => break,
|
ClientInstruction::Exit => break,
|
||||||
ClientInstruction::Error(backtrace) => {
|
ClientInstruction::Error(backtrace) => {
|
||||||
let _ = os_input.send_to_server(ClientToServerMsg::ClientExit);
|
let _ = os_input.send_to_server(ClientToServerMsg::Action(Action::Quit));
|
||||||
handle_error(backtrace);
|
handle_error(backtrace);
|
||||||
}
|
}
|
||||||
ClientInstruction::ServerError(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();
|
router_thread.join().unwrap();
|
||||||
|
|
||||||
// cleanup();
|
// cleanup();
|
||||||
|
|
|
||||||
|
|
@ -49,11 +49,9 @@ pub(crate) enum ServerInstruction {
|
||||||
impl From<ClientToServerMsg> for ServerInstruction {
|
impl From<ClientToServerMsg> for ServerInstruction {
|
||||||
fn from(instruction: ClientToServerMsg) -> Self {
|
fn from(instruction: ClientToServerMsg) -> Self {
|
||||||
match instruction {
|
match instruction {
|
||||||
ClientToServerMsg::ClientExit => ServerInstruction::ClientExit,
|
|
||||||
ClientToServerMsg::NewClient(pos, opts, options) => {
|
ClientToServerMsg::NewClient(pos, opts, options) => {
|
||||||
ServerInstruction::NewClient(pos, opts, options)
|
ServerInstruction::NewClient(pos, opts, options)
|
||||||
}
|
}
|
||||||
ClientToServerMsg::DetachSession => ServerInstruction::DetachSession,
|
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,13 @@ use zellij_utils::{
|
||||||
ipc::ClientToServerMsg,
|
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 {
|
match action {
|
||||||
Action::Write(val) => {
|
Action::Write(val) => {
|
||||||
session
|
session
|
||||||
|
|
@ -182,9 +188,17 @@ fn route_action(action: Action, session: &SessionMetaData, os_input: &dyn Server
|
||||||
.send_to_screen(ScreenInstruction::UpdateTabName(c))
|
.send_to_screen(ScreenInstruction::UpdateTabName(c))
|
||||||
.unwrap();
|
.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::NoOp => {}
|
||||||
Action::Quit => panic!("Received unexpected action"),
|
|
||||||
}
|
}
|
||||||
|
should_break
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn route_thread_main(
|
pub(crate) fn route_thread_main(
|
||||||
|
|
@ -197,13 +211,11 @@ pub(crate) fn route_thread_main(
|
||||||
err_ctx.update_thread_ctx();
|
err_ctx.update_thread_ctx();
|
||||||
let rlocked_sessions = session_data.read().unwrap();
|
let rlocked_sessions = session_data.read().unwrap();
|
||||||
match instruction {
|
match instruction {
|
||||||
ClientToServerMsg::ClientExit | ClientToServerMsg::DetachSession => {
|
|
||||||
to_server.send(instruction.into()).unwrap();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ClientToServerMsg::Action(action) => {
|
ClientToServerMsg::Action(action) => {
|
||||||
if let Some(rlocked_sessions) = rlocked_sessions.as_ref() {
|
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) => {
|
ClientToServerMsg::TerminalResize(new_size) => {
|
||||||
|
|
|
||||||
|
|
@ -65,4 +65,6 @@ pub enum Action {
|
||||||
CloseTab,
|
CloseTab,
|
||||||
GoToTab(u32),
|
GoToTab(u32),
|
||||||
TabNameInput(Vec<u8>),
|
TabNameInput(Vec<u8>),
|
||||||
|
/// Detach session and exit
|
||||||
|
Detach,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,11 +54,9 @@ pub enum ClientToServerMsg {
|
||||||
DetachSession(SessionId),
|
DetachSession(SessionId),
|
||||||
// Disconnect from the session we're connected to
|
// Disconnect from the session we're connected to
|
||||||
DisconnectFromSession,*/
|
DisconnectFromSession,*/
|
||||||
ClientExit,
|
|
||||||
TerminalResize(PositionAndSize),
|
TerminalResize(PositionAndSize),
|
||||||
NewClient(ClientAttributes, Box<CliArgs>, Box<Options>),
|
NewClient(ClientAttributes, Box<CliArgs>, Box<Options>),
|
||||||
Action(Action),
|
Action(Action),
|
||||||
DetachSession,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Types of messages sent from the server to the client
|
// Types of messages sent from the server to the client
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue