fn compare_using_fd_with_stty() {
    use std::process::Command;
    use std::process::Stdio;

    let output = if cfg!(target_os = "macos") {
        Command::new("stty")
            .arg("-f")
            .arg("/dev/stderr")
            .arg("size")
            .stderr(Stdio::inherit())
            .output()
            .unwrap()
    } else {
        Command::new("stty")
            .arg("size")
            .arg("-F")
            .arg("/dev/stderr")
            .stderr(Stdio::inherit())
            .output()
            .unwrap()
    };
    let stdout = String::from_utf8(output.stdout).unwrap();
    assert!(output.status.success());
    // stdout is "rows cols"
    let mut data = stdout.split_whitespace();
    let rows = u16::from_str_radix(data.next().unwrap(), 10).unwrap();
    let cols = u16::from_str_radix(data.next().unwrap(), 10).unwrap();
    println!("{}", stdout);
    println!("{} {}", rows, cols);

    if let Some((Width(w), Height(h))) = terminal_size_using_fd() {
        assert_eq!(rows, h);
        assert_eq!(cols, w);
    }
}
/// Compare using_fd with the output of `stty size`
Compare using_fd with the output of `stty size`
Compare using_fd with the output of ` stty size `
fn compare_using_fd_with_stty() {
    use std::process::Command;
    use std::process::Stdio;
    let output = if cfg!(target_os = "macos") {
        Command::new("stty")
            .arg("-f")
            .arg("/dev/stderr")
            .arg("size")
            .stderr(Stdio::inherit())
            .output()
            .unwrap()
    } else {
        Command::new("stty")
            .arg("size")
            .arg("-F")
            .arg("/dev/stderr")
            .stderr(Stdio::inherit())
            .output()
            .unwrap()
    };
    let stdout = String::from_utf8(output.stdout).unwrap();
    assert!(output.status.success());
    // stdout is "rows cols"
    let mut data = stdout.split_whitespace();
    let rows = u16::from_str_radix(data.next().unwrap(), 10).unwrap();
    let cols = u16::from_str_radix(data.next().unwrap(), 10).unwrap();
    println!("{}", stdout);
    println!("{} {}", rows, cols);
    if let Some((Width(w), Height(h))) = terminal_size_using_fd() {
        assert_eq!(rows, h);
        assert_eq!(cols, w);
    }
}
fn compare_using_fd_with_stty ( ) { use std :: process :: Command ; use std :: process :: Stdio ; let output = if cfg ! ( target_os " " ) { Command :: new ( " " ) . arg ( " " ) . arg ( " " ) . arg ( " " ) . stderr ( Stdio :: inherit ( ) ) . output ( ) . unwrap ( ) } else { Command :: new ( " " ) . arg ( " " ) . arg ( " " ) . arg ( " " ) . stderr ( Stdio :: inherit ( ) ) . output ( ) . unwrap ( ) } ; let stdout = String :: from_utf8 ( output . stdout ) . unwrap ( ) ; assert ! ( output status success ( ) ) ; // stdout is "rows cols" let mut data = stdout . split_whitespace ( ) ; let rows = u16 :: from_str_radix ( data . next ( ) . unwrap ( ) , 10 ) . unwrap ( ) ; let cols = u16 :: from_str_radix ( data . next ( ) . unwrap ( ) , 10 ) . unwrap ( ) ; println ! ( " " stdout ) ; println ! ( " " rows cols ) ; if let Some ( ( Width ( w ) , Height ( h ) ) ) = terminal_size_using_fd ( ) { assert_eq ! ( rows h ) ; assert_eq ! ( cols w ) ; } }
Compare using_fd with the output of `stty size`
Compare using_fd with the output of ` stty size `