Skip to content

Commit

Permalink
Be more defensive with /dev/tty (denisidoro#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
denisidoro authored Mar 10, 2020
1 parent aefc136 commit 44d072d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 44d072d

Please sign in to comment.