Skip to content

Commit

Permalink
Merge pull request #102 from gwenn/winsize
Browse files Browse the repository at this point in the history
Use libc winsize and TIOCGWINSZ
  • Loading branch information
kkawakam authored Dec 6, 2016
2 parents 43fc4f5 + d1fa71c commit ec773db
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions src/tty/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down

0 comments on commit ec773db

Please sign in to comment.