Skip to content

Commit

Permalink
Merge pull request #61 from mneumann/fix-dragonfly-freebsd
Browse files Browse the repository at this point in the history
Fix for DragonFly and FreeBSD
  • Loading branch information
a8m authored Jan 2, 2018
2 parents c63c368 + 5b469a7 commit d077b49
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ keywords = ["cli", "progress", "terminal", "pb"]
license = "MIT"

[dependencies]
libc = "0.2.9"
libc = "0.2"
time = "0.1.35"

[target.'cfg(target_os = "windows")'.dependencies]
Expand Down
10 changes: 9 additions & 1 deletion src/tty/unix.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
extern crate libc;
use super::{Width, Height};

// We need to convert from c_int to c_ulong at least on DragonFly and FreeBSD.
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
fn ioctl_conv<T: Into<libc::c_ulong>>(v: T) -> libc::c_ulong { v.into() }

// No-op on any other operating system.
#[cfg(not(any(target_os = "dragonfly", target_os = "freebsd")))]
fn ioctl_conv<T: Copy>(v: T) -> T { v }

/// Returns the size of the terminal, if available.
///
/// If STDOUT is not a tty, returns `None`
Expand All @@ -19,7 +27,7 @@ pub fn terminal_size() -> Option<(Width, Height)> {
ws_xpixel: 0,
ws_ypixel: 0,
};
ioctl(STDOUT_FILENO, TIOCGWINSZ, &mut winsize);
ioctl(STDOUT_FILENO, ioctl_conv(TIOCGWINSZ), &mut winsize);
let rows = if winsize.ws_row > 0 {
winsize.ws_row
} else {
Expand Down

0 comments on commit d077b49

Please sign in to comment.