From d1fa71c9d2c1ec1b0385ee207b8ce13031f1f6cd Mon Sep 17 00:00:00 2001 From: gwenn Date: Sun, 4 Dec 2016 09:29:42 +0100 Subject: [PATCH] Use libc winsize and TIOCGWINSZ --- src/tty/unix.rs | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/src/tty/unix.rs b/src/tty/unix.rs index b3aa8285ee..a4e43631b7 100644 --- a/src/tty/unix.rs +++ b/src/tty/unix.rs @@ -21,30 +21,12 @@ const STDOUT_FILENO: libc::c_int = libc::STDOUT_FILENO; /// Unsupported Terminals that don't support RAW mode static UNSUPPORTED_TERM: [&'static str; 3] = ["dumb", "cons25", "emacs"]; -#[cfg(any(target_os = "macos", target_os = "freebsd"))] -const TIOCGWINSZ: libc::c_ulong = 0x40087468; - -#[cfg(any(all(target_os = "linux", target_env = "gnu"), target_os = "android"))] -const TIOCGWINSZ: libc::c_ulong = 0x5413; - -#[cfg(all(target_os = "linux", target_env = "musl"))] -const TIOCGWINSZ: libc::c_int = 0x5413; - fn get_win_size() -> (usize, usize) { use std::mem::zeroed; - use libc::c_ushort; unsafe { - #[repr(C)] - struct winsize { - ws_row: c_ushort, - ws_col: c_ushort, - ws_xpixel: c_ushort, - ws_ypixel: c_ushort, - } - - let mut size: winsize = zeroed(); - match libc::ioctl(STDOUT_FILENO, TIOCGWINSZ, &mut size) { + let mut size: libc::winsize = zeroed(); + match libc::ioctl(STDOUT_FILENO, libc::TIOCGWINSZ, &mut size) { 0 => (size.ws_col as usize, size.ws_row as usize), // TODO getCursorPosition _ => (80, 24), }