Skip to content

Commit

Permalink
Reuse helper, reduce scope of unsafe block
Browse files Browse the repository at this point in the history
  • Loading branch information
tamird committed Dec 16, 2024
1 parent 11d3f63 commit 35d0451
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/unix_term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ fn c_result<F: FnOnce() -> libc::c_int>(f: F) -> io::Result<()> {
}

pub(crate) fn terminal_size(out: &Term) -> Option<(u16, u16)> {
unsafe {
if libc::isatty(out.as_raw_fd()) != 1 {
return None;
}

if !is_a_terminal(out) {
return None;
}
let winsize = unsafe {
let mut winsize: libc::winsize = mem::zeroed();

// FIXME: ".into()" used as a temporary fix for a libc bug
// https://github.com/rust-lang/libc/pull/704
#[allow(clippy::useless_conversion)]
libc::ioctl(out.as_raw_fd(), libc::TIOCGWINSZ.into(), &mut winsize);
if winsize.ws_row > 0 && winsize.ws_col > 0 {
Some((winsize.ws_row as u16, winsize.ws_col as u16))
} else {
None
}
winsize
};
if winsize.ws_row > 0 && winsize.ws_col > 0 {
Some((winsize.ws_row as u16, winsize.ws_col as u16))
} else {
None
}
}

Expand Down

0 comments on commit 35d0451

Please sign in to comment.