pub fn terminal_size_using_fd() -> Option<(Width, Height)> {
    use self::libc::STDOUT_FILENO;
    use self::libc::ioctl;
    use self::libc::isatty;

    let fd = STDOUT_FILENO;
    let is_tty: bool = unsafe { isatty(fd) == 1 };

    if !is_tty {
        return None;
    }

    let (rows, cols) = unsafe {
        let mut winsize = WinSize {
            ws_row: 0,
            ws_col: 0,
            ws_xpixel: 0,
            ws_ypixel: 0,
        };
        ioctl(fd, TIOCGWINSZ, &mut winsize);
        let rows = if winsize.ws_row > 0 {
            winsize.ws_row
        } else {
            0
        };
        let cols = if winsize.ws_col > 0 {
            winsize.ws_col
        } else {
            0
        };
        (rows as u16, cols as u16)
    };

    Some((Width(cols), Height(rows)))
}
/// Returns the size of the terminal using the given file descriptor, if available.
///
/// If the STDOUT file descriptor is not a tty, returns `None`
Returns the size of the terminal using the given file descriptor, if available.
If the STDOUT file descriptor is not a tty, returns `None`
Returns the size of the terminal using the given file descriptor if available . If the STDOUT file descriptor is not a tty returns ` None `
pub fn terminal_size_using_fd() -> Option<(Width, Height)> {
    use self::libc::STDOUT_FILENO;
    use self::libc::ioctl;
    use self::libc::isatty;
    let fd = STDOUT_FILENO;
    let is_tty: bool = unsafe { isatty(fd) == 1 };
    if !is_tty {
        return None;
    }
    let (rows, cols) = unsafe {
        let mut winsize = WinSize {
            ws_row: 0,
            ws_col: 0,
            ws_xpixel: 0,
            ws_ypixel: 0,
        };
        ioctl(fd, TIOCGWINSZ, &mut winsize);
        let rows = if winsize.ws_row > 0 {
            winsize.ws_row
        } else {
            0
        };
        let cols = if winsize.ws_col > 0 {
            winsize.ws_col
        } else {
            0
        };
        (rows as u16, cols as u16)
    };
    Some((Width(cols), Height(rows)))
}
pub fn terminal_size_using_fd ( ) -> Option < ( Width , Height ) > { use self :: libc :: STDOUT_FILENO ; use self :: libc :: ioctl ; use self :: libc :: isatty ; let fd = STDOUT_FILENO ; let is_tty : bool = unsafe { isatty ( fd ) == 1 } ; if ! is_tty { return None ; } let ( rows , cols ) = unsafe { let mut winsize = WinSize { ws_row : 0 , ws_col : 0 , ws_xpixel : 0 , ws_ypixel : 0 , } ; ioctl ( fd , TIOCGWINSZ , & mut winsize ) ; let rows = if winsize . ws_row > 0 { winsize . ws_row } else { 0 } ; let cols = if winsize . ws_col > 0 { winsize . ws_col } else { 0 } ; ( rows as u16 , cols as u16 ) } ; Some ( ( Width ( cols ) , Height ( rows ) ) ) }
Returns the size of the terminal using the given file descriptor, if available.
Returns the size of the terminal using the given file descriptor if available .