tag | 77630d7e2bf9427b9145f8a355f1af5200758d10 | |
---|---|---|
tagger | The Android Open Source Project <initial-contribution@android.com> | Tue Apr 23 15:27:30 2024 -0700 |
object | 51079d07053732c6d1ed0b1d071bb5857f025e00 |
Platform Tools Release 35.0.1 (11580240)
commit | 51079d07053732c6d1ed0b1d071bb5857f025e00 | [log] [tgz] |
---|---|---|
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Thu Mar 07 02:13:46 2024 +0000 |
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Thu Mar 07 02:13:46 2024 +0000 |
tree | 8a2f8ca02a855a7e6380a49522514fc34d302757 | |
parent | 484fbc58949be92294664dcc4a0d4b60e3177e46 [diff] | |
parent | 4ea1424c923562895ab5f32af0d2fb128e19e2c8 [diff] |
Snap for 11541002 from 4ea1424c923562895ab5f32af0d2fb128e19e2c8 to sdk-release Change-Id: Ib45b3750a78fc621874e68fdc43370dcffe51296
are you or are you not a tty?
Add the following to your Cargo.toml
[dependencies] atty = "0.2"
use atty::Stream; fn main() { if atty::is(Stream::Stdout) { println!("I'm a terminal"); } else { println!("I'm not"); } }
This library has been unit tested on both unix and windows platforms (via appveyor).
A simple example program is provided in this repo to test various tty's. By default.
It prints
$ cargo run --example atty stdout? true stderr? true stdin? true
To test std in, pipe some text to the program
$ echo "test" | cargo run --example atty stdout? true stderr? true stdin? false
To test std out, pipe the program to something
$ cargo run --example atty | grep std stdout? false stderr? true stdin? true
To test std err, pipe the program to something redirecting std err
$ cargo run --example atty 2>&1 | grep std stdout? false stderr? false stdin? true
Doug Tangren (softprops) 2015-2019