• Home
Name
Date
Size
#Lines
LOC

..--

.github/12-May-2024-177142

examples/12-May-2024-86

src/12-May-2024-373272

.gitignoreD12-May-202423 43

BUILD.gnD12-May-20241.1 KiB3228

Cargo.tomlD12-May-20241.1 KiB4335

LICENSE-MITD12-May-20241,023 2421

LICENSE-MIT-attyD12-May-20241.1 KiB2419

README.OpenSourceD12-May-2024351 1111

README.mdD12-May-20243.1 KiB10579

README.OpenSource

1[
2  {
3    "Name": "is-terminal",
4    "License": "MIT",
5    "License File": "LICENSE-MIT, LICENSE-MIT-atty",
6    "Version Number": "0.4.3",
7    "Owner": "fangting12@huawei.com",
8    "Upstream URL": "https://github.com/sunfishcode/is-terminal",
9    "Description": "A Rust library that provides support for detecting whether a terminal is present."
10  }
11]

README.md

1<div align="center">
2  <h1><code>is-terminal</code></h1>
3
4  <p>
5    <strong>Test whether a given stream is a terminal</strong>
6  </p>
7
8  <p>
9    <a href="https://github.com/sunfishcode/is-terminal/actions?query=workflow%3ACI"><img src="https://github.com/sunfishcode/is-terminal/workflows/CI/badge.svg" alt="Github Actions CI Status" /></a>
10    <a href="https://crates.io/crates/is-terminal"><img src="https://img.shields.io/crates/v/is-terminal.svg" alt="crates.io page" /></a>
11    <a href="https://docs.rs/is-terminal"><img src="https://docs.rs/is-terminal/badge.svg" alt="docs.rs docs" /></a>
12  </p>
13</div>
14
15is-terminal is a simple utility that answers one question:
16
17> Is this a terminal?
18
19A "terminal", also known as a "tty", is an I/O device which may be interactive
20and may support color and other special features. This crate doesn't provide
21any of those features; it just answers this one question.
22
23On Unix-family platforms, this is effectively the same as the [`isatty`]
24function for testing whether a given stream is a terminal, though it accepts
25high-level stream types instead of raw file descriptors.
26
27On Windows, it uses a variety of techniques to determine whether the given
28stream is a terminal.
29
30This crate is derived from [the atty crate] with [PR \#51] bug fix and
31[PR \#54] port to windows-sys applied. The only additional difference is that
32the atty crate only accepts stdin, stdout, or stderr, while this crate accepts
33any stream. In particular, this crate does not access any stream that is not
34passed to it, in accordance with [I/O safety].
35
36[PR \#51]: https://github.com/softprops/atty/pull/51
37[PR \#54]: https://github.com/softprops/atty/pull/54
38
39## Example
40
41```rust
42use is_terminal::IsTerminal;
43
44fn main() {
45    if std::io::stdout().is_terminal() {
46        println!("Stdout is a terminal");
47    } else {
48        println!("Stdout is not a terminal");
49    }
50}
51```
52
53## Testing
54
55This library is tested on both Unix-family and Windows platforms.
56
57To test it on a platform manually, use the provided `stdio` example program.
58When run normally, it prints this:
59
60```bash
61$ cargo run --example stdio
62stdin? true
63stdout? true
64stderr? true
65```
66
67To test stdin, pipe some text to the program:
68
69```bash
70$ cat | cargo run --example stdio
71stdin? false
72stdout? true
73stderr? true
74```
75
76To test stdout, pipe the program to something:
77
78```bash
79$ cargo run --example stdio | cat
80stdin? true
81stdout? false
82stderr? true
83```
84
85To test stderr, pipe the program to something redirecting stderr:
86
87```bash
88$ cargo run --example stdio 2>&1 | cat
89stdin? true
90stdout? false
91stderr? false
92```
93
94# Minimum Supported Rust Version (MSRV)
95
96This crate currently works on the version of [Rust on Debian stable], which is
97currently Rust 1.48. This policy may change in the future, in minor version
98releases, so users using a fixed version of Rust should pin to a specific
99version of this crate.
100
101[`isatty`]: https://man7.org/linux/man-pages/man3/isatty.3.html
102[the atty crate]: https://crates.io/crates/atty
103[I/O safety]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md
104[Rust on Debian stable]: https://packages.debian.org/stable/rust/rustc
105