diff options
-rw-r--r-- | src/commands.rs | 2 | ||||
-rw-r--r-- | zellij-client/src/os_input_output.rs | 25 |
2 files changed, 22 insertions, 5 deletions
diff --git a/src/commands.rs b/src/commands.rs index e9ab951bc..5f93295a4 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -237,7 +237,7 @@ pub(crate) fn convert_old_theme_file(old_theme_file: PathBuf) { } fn attach_with_cli_client(cli_action: zellij_utils::cli::CliAction, session_name: &str) { - let os_input = get_os_input(zellij_client::os_input_output::get_client_os_input); + let os_input = get_os_input(zellij_client::os_input_output::get_cli_client_os_input); match Action::actions_from_cli(cli_action) { Ok(actions) => { zellij_client::cli_client::start_cli_client(Box::new(os_input), session_name, actions); diff --git a/zellij-client/src/os_input_output.rs b/zellij-client/src/os_input_output.rs index 8004b8ad2..192c2159d 100644 --- a/zellij-client/src/os_input_output.rs +++ b/zellij-client/src/os_input_output.rs @@ -75,7 +75,7 @@ pub(crate) fn get_terminal_size_using_fd(fd: RawFd) -> Size { #[derive(Clone)] pub struct ClientOsInputOutput { - orig_termios: Arc<Mutex<termios::Termios>>, + orig_termios: Option<Arc<Mutex<termios::Termios>>>, send_instructions_to_server: Arc<Mutex<Option<IpcSenderWithContext<ClientToServerMsg>>>>, receive_instructions_from_server: Arc<Mutex<Option<IpcReceiverWithContext<ServerToClientMsg>>>>, } @@ -121,8 +121,16 @@ impl ClientOsApi for ClientOsInputOutput { into_raw_mode(fd); } fn unset_raw_mode(&self, fd: RawFd) -> Result<(), nix::Error> { - let orig_termios = self.orig_termios.lock().unwrap(); - unset_raw_mode(fd, orig_termios.clone()) + match &self.orig_termios { + Some(orig_termios) => { + let orig_termios = orig_termios.lock().unwrap(); + unset_raw_mode(fd, orig_termios.clone()) + }, + None => { + log::warn!("trying to unset raw mode for a non-terminal session"); + Ok(()) + }, + } } fn box_clone(&self) -> Box<dyn ClientOsApi> { Box::new((*self).clone()) @@ -249,7 +257,16 @@ impl Clone for Box<dyn ClientOsApi> { pub fn get_client_os_input() -> Result<ClientOsInputOutput, nix::Error> { let current_termios = termios::tcgetattr(0)?; - let orig_termios = Arc::new(Mutex::new(current_termios)); + let orig_termios = Some(Arc::new(Mutex::new(current_termios))); + Ok(ClientOsInputOutput { + orig_termios, + send_instructions_to_server: Arc::new(Mutex::new(None)), + receive_instructions_from_server: Arc::new(Mutex::new(None)), + }) +} + +pub fn get_cli_client_os_input() -> Result<ClientOsInputOutput, nix::Error> { + let orig_termios = None; // not a terminal Ok(ClientOsInputOutput { orig_termios, send_instructions_to_server: Arc::new(Mutex::new(None)), |