commit | 972eeef8db6d54c273736c84e154f2d181412cc2 | [log] [tgz] |
---|---|---|
author | Matthew Maurer <mmaurer@google.com> | Tue Mar 07 17:23:24 2023 -0800 |
committer | Matthew Maurer <mmaurer@google.com> | Tue Mar 07 17:23:24 2023 -0800 |
tree | c582cd4a56d60253952c8c33beb566135f5fb6f5 | |
parent | b2486ad9e829b8b175ed96970ccc41d7167b748f [diff] |
Make atty available to product and vendor Bug: 270690570 Test: mma in external/rust/crates Change-Id: Ia7b0857fe52b3be087b222e4f874e63554c3525c
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