32-bit support
This commit is contained in:
parent
22ef240967
commit
efcc232de1
16
src/size.rs
16
src/size.rs
|
@ -12,18 +12,30 @@ struct TermSize {
|
|||
_y: c_ushort,
|
||||
}
|
||||
|
||||
// Since attributes on non-item statements is not stable yet, we use a function.
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
fn tiocgwinsz() -> u64 {
|
||||
use termios::TIOCGWINSZ;
|
||||
TIOCGWINSZ as u64
|
||||
}
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
fn tiocgwinsz() -> u32 {
|
||||
use termios::TIOCGWINSZ;
|
||||
TIOCGWINSZ as u32
|
||||
}
|
||||
|
||||
|
||||
/// Get the size of the terminal.
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
pub fn terminal_size() -> Result<(usize, usize), TerminalError> {
|
||||
use libc::ioctl;
|
||||
use libc::STDOUT_FILENO;
|
||||
use termios::TIOCGWINSZ;
|
||||
|
||||
use std::mem;
|
||||
unsafe {
|
||||
let mut size: TermSize = mem::zeroed();
|
||||
|
||||
if ioctl(STDOUT_FILENO, TIOCGWINSZ, &mut size as *mut _) == 0 {
|
||||
if ioctl(STDOUT_FILENO, tiocgwinsz(), &mut size as *mut _) == 0 {
|
||||
Ok((size.col as usize, size.row as usize))
|
||||
} else {
|
||||
Err(TerminalError::TermSizeError)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use libc::{c_int, c_uint, c_uchar};
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub const TIOCGWINSZ: u64 = 0x00005413;
|
||||
pub const TIOCGWINSZ: usize = 0x00005413;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub const TIOCGWINSZ: u64 = 0x40087468;
|
||||
pub const TIOCGWINSZ: usize = 0x40087468;
|
||||
|
||||
extern {
|
||||
pub fn tcgetattr(filedes: c_int, termptr: *mut Termios) -> c_int;
|
||||
|
|
Loading…
Reference in New Issue