Go to file
openharmony_ci 46f3454816
!2 Add OAT.xml and README.OpenSource
Merge pull request !2 from fangting/master
2023-04-14 08:10:01 +00:00
examples Revert "upgrade to 2018 edition" 2019-07-15 22:50:56 -04:00
src add support of the unikernel RustyHermit 2020-01-04 09:09:15 +01:00
.gitignore ignore rustfmt artifacts 2016-09-11 23:31:00 -04:00
.travis.yml just test building 2017-09-30 14:51:55 -04:00
appveyor.yml just test building 2017-09-30 14:51:55 -04:00
BUILD.gn Add GN Build Files and Custom Modifications 2023-04-12 17:25:43 +08:00
Cargo.toml prep release 2020-01-05 17:09:31 -05:00
CHANGELOG.md prep release 2020-01-05 17:09:31 -05:00
LICENSE update readme example for 2018 edition rust 2019-07-11 19:31:14 -04:00
README.md update readme example for 2018 edition rust 2019-07-11 19:31:14 -04:00
README.OpenSource Add OAT.xml and README.OpenSource 2023-04-14 14:14:36 +08:00
rustfmt.toml update rustfmt settings 2019-07-11 19:25:14 -04:00

atty

Build Status Build status Coverage Status crates.io Released API docs Master API docs

are you or are you not a tty?

install

Add the following to your Cargo.toml

[dependencies]
atty = "0.2"

usage

use atty::Stream;

fn main() {
  if atty::is(Stream::Stdout) {
    println!("I'm a terminal");
  } else {
    println!("I'm not");
  }
}

testing

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