#[derive(Debug)]
pub struct Size {
pub col: usize,
pub row: usize,
}
#[cfg(unix)]
mod unix;
#[cfg(unix)]
pub use self::unix::{term_cols, term_size};
#[cfg(windows)]
mod windows;
#[cfg(windows)]
pub use self::windows::{term_cols, term_size};
#[cfg(not(any(unix, windows)))]
mod unknown;
#[cfg(not(any(unix, windows)))]
pub use self::unknown::{term_cols, term_size};
#[cfg(test)]
mod test_of_term_cols {
use super::*;
#[cfg(unix)]
#[test]
fn test_get_terminal_cols() {
match term_cols() {
Ok(c) => println!("term cols = {}", c),
Err(e) => {
println!("term cols error = {}", e.to_string());
assert_eq!(e.raw_os_error().unwrap(), 25); }
}
}
#[cfg(windows)]
#[test]
fn test_get_terminal_cols() {
match term_cols() {
Ok(c) => println!("term cols = {}", c),
Err(e) => {
println!("term cols error = {}", e.to_string());
assert_eq!(e.raw_os_error().unwrap() & 0xffff, 6); }
}
}
#[cfg(not(any(unix, windows)))]
#[test]
fn test_get_terminal_cols() {
match term_cols() {
Ok(cols) => assert!(false),
Err(e) => assert_eq!(e.kind(), ErrorKind::Unsupported),
}
}
}
#[cfg(test)]
mod test_of_term_size {
use super::*;
#[cfg(unix)]
#[test]
fn test_get_terminal_size() {
match term_size() {
Ok(sz) => println!("term size = {} x {}", sz.col, sz.row),
Err(e) => {
println!("term size error = {}", e.to_string());
assert_eq!(e.raw_os_error().unwrap(), 25); }
}
}
#[cfg(windows)]
#[test]
fn test_get_terminal_size() {
match term_size() {
Ok(sz) => println!("term size = {} x {}", sz.col, sz.row),
Err(e) => {
println!("term size error = {}", e.to_string());
assert_eq!(e.raw_os_error().unwrap() & 0xffff, 6); }
}
}
#[cfg(not(any(unix, windows)))]
#[test]
fn test_get_terminal_cols() {
match term_cols() {
Ok(cols) => assert!(false),
Err(e) => assert_eq!(e.kind(), ErrorKind::Unsupported),
}
}
}