handle error on termios initialization (#511)
This commit is contained in:
parent
8d742ccc53
commit
28212f5430
2 changed files with 22 additions and 10 deletions
|
|
@ -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)]
|
||||
|
|
@ -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
src/main.rs
16
src/main.rs
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue