diff --git a/src/commands.rs b/src/commands.rs index e9ab951b..5f93295a 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 8004b8ad..192c2159 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>, + orig_termios: Option>>, send_instructions_to_server: Arc>>>, receive_instructions_from_server: Arc>>>, } @@ -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 { Box::new((*self).clone()) @@ -249,7 +257,16 @@ impl Clone for Box { pub fn get_client_os_input() -> Result { 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 { + let orig_termios = None; // not a terminal Ok(ClientOsInputOutput { orig_termios, send_instructions_to_server: Arc::new(Mutex::new(None)),