This commit is contained in:
2020-01-30 21:04:30 +08:00
parent ce78aa2a93
commit 447e8cf673
2 changed files with 31 additions and 0 deletions

18
term/src/main.rs Normal file
View File

@@ -0,0 +1,18 @@
use atty::Stream;
// https://crates.io/crates/atty
// https://rosettacode.org/wiki/Check_output_device_is_a_terminal
fn main() {
if atty::is(Stream::Stdout) {
println!("I'm a terminal");
} else {
println!("I'm not");
}
let istty = unsafe { libc::isatty(libc::STDOUT_FILENO as i32) } != 0;
if istty {
println!("stdout is tty");
} else {
println!("stdout is not tty");
}
}