Be more defensive with /dev/tty (#219)

This commit is contained in:
Denis Isidoro 2020-03-10 13:32:22 -03:00 committed by GitHub
parent aefc136491
commit 44d072de94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -37,11 +37,16 @@ fn width_with_fd() -> u16 {
use std::fs;
use std::os::unix::io::AsRawFd;
let file = fs::File::open("/dev/tty").unwrap();
let size = terminal_size_using_fd(file.as_raw_fd());
let file = fs::File::open("/dev/tty");
if let Some((Width(w), Height(_))) = size {
w
if let Ok(f) = file {
let size = terminal_size_using_fd(f.as_raw_fd());
if let Some((Width(w), Height(_))) = size {
w
} else {
width_with_shell_out()
}
} else {
width_with_shell_out()
}