add term
This commit is contained in:
13
term/Cargo.toml
Normal file
13
term/Cargo.toml
Normal file
@@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "term"
|
||||
version = "0.1.0"
|
||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
libc = "0.2.65"
|
||||
atty = "0.2.13"
|
||||
|
||||
|
||||
18
term/src/main.rs
Normal file
18
term/src/main.rs
Normal 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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user