Skip to content

Commit 58afd15

Browse files
tamirddjc
authored andcommitted
Reuse helper, reduce scope of unsafe block
1 parent 383fcce commit 58afd15

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/unix_term.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,22 @@ fn c_result<F: FnOnce() -> libc::c_int>(f: F) -> io::Result<()> {
4747
}
4848

4949
pub(crate) fn terminal_size(out: &Term) -> Option<(u16, u16)> {
50-
unsafe {
51-
if libc::isatty(out.as_raw_fd()) != 1 {
52-
return None;
53-
}
54-
50+
if !is_a_terminal(out) {
51+
return None;
52+
}
53+
let winsize = unsafe {
5554
let mut winsize: libc::winsize = mem::zeroed();
5655

5756
// FIXME: ".into()" used as a temporary fix for a libc bug
5857
// https://github.com/rust-lang/libc/pull/704
5958
#[allow(clippy::useless_conversion)]
6059
libc::ioctl(out.as_raw_fd(), libc::TIOCGWINSZ.into(), &mut winsize);
61-
if winsize.ws_row > 0 && winsize.ws_col > 0 {
62-
Some((winsize.ws_row as u16, winsize.ws_col as u16))
63-
} else {
64-
None
65-
}
60+
winsize
61+
};
62+
if winsize.ws_row > 0 && winsize.ws_col > 0 {
63+
Some((winsize.ws_row as u16, winsize.ws_col as u16))
64+
} else {
65+
None
6666
}
6767
}
6868

0 commit comments

Comments
 (0)