Skip to content

Commit

Permalink
handle error on termios initialization (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlinford authored May 16, 2021
1 parent 8d742cc commit 28212f5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/common/os_input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,14 @@ impl Clone for Box<dyn ServerOsApi> {
}
}

pub fn get_server_os_input() -> ServerOsInputOutput {
let current_termios = termios::tcgetattr(0).unwrap();
pub fn get_server_os_input() -> Result<ServerOsInputOutput, nix::Error> {
let current_termios = termios::tcgetattr(0)?;
let orig_termios = Arc::new(Mutex::new(current_termios));
ServerOsInputOutput {
Ok(ServerOsInputOutput {
orig_termios,
receive_instructions_from_client: None,
send_instructions_to_client: Arc::new(Mutex::new(None)),
}
})
}

#[derive(Clone)]
Expand Down Expand Up @@ -403,12 +403,12 @@ impl Clone for Box<dyn ClientOsApi> {
}
}

pub fn get_client_os_input() -> ClientOsInputOutput {
let current_termios = termios::tcgetattr(0).unwrap();
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));
ClientOsInputOutput {
Ok(ClientOsInputOutput {
orig_termios,
send_instructions_to_server: Arc::new(Mutex::new(None)),
receive_instructions_from_server: Arc::new(Mutex::new(None)),
}
})
}
16 changes: 14 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,22 @@ pub fn main() {
atomic_create_dir(&*ZELLIJ_TMP_DIR).unwrap();
atomic_create_dir(&*ZELLIJ_TMP_LOG_DIR).unwrap();
if let Some(path) = opts.server {
let os_input = get_server_os_input();
let os_input = match get_server_os_input() {
Ok(server_os_input) => server_os_input,
Err(e) => {
eprintln!("failed to open terminal:\n{}", e);
std::process::exit(1);
}
};
start_server(Box::new(os_input), path);
} else {
let os_input = get_client_os_input();
let os_input = match get_client_os_input() {
Ok(os_input) => os_input,
Err(e) => {
eprintln!("failed to open terminal:\n{}", e);
std::process::exit(1);
}
};
start_client(Box::new(os_input), opts, config);
}
}
Expand Down

0 comments on commit 28212f5

Please sign in to comment.