4 Star 0 Fork 5

OpenHarmony / third_party_rust_is-terminal

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README
MIT

is-terminal

Test whether a given stream is a terminal

Github Actions CI Status crates.io page docs.rs docs

is-terminal is a simple utility that answers one question:

Is this a terminal?

A "terminal", also known as a "tty", is an I/O device which may be interactive and may support color and other special features. This crate doesn't provide any of those features; it just answers this one question.

On Unix-family platforms, this is effectively the same as the isatty function for testing whether a given stream is a terminal, though it accepts high-level stream types instead of raw file descriptors.

On Windows, it uses a variety of techniques to determine whether the given stream is a terminal.

This crate is derived from the atty crate with PR #51 bug fix and PR #54 port to windows-sys applied. The only additional difference is that the atty crate only accepts stdin, stdout, or stderr, while this crate accepts any stream. In particular, this crate does not access any stream that is not passed to it, in accordance with I/O safety.

Example

use is_terminal::IsTerminal;

fn main() {
    if std::io::stdout().is_terminal() {
        println!("Stdout is a terminal");
    } else {
        println!("Stdout is not a terminal");
    }
}

Testing

This library is tested on both Unix-family and Windows platforms.

To test it on a platform manually, use the provided stdio example program. When run normally, it prints this:

$ cargo run --example stdio
stdin? true
stdout? true
stderr? true

To test stdin, pipe some text to the program:

$ cat | cargo run --example stdio
stdin? false
stdout? true
stderr? true

To test stdout, pipe the program to something:

$ cargo run --example stdio | cat
stdin? true
stdout? false
stderr? true

To test stderr, pipe the program to something redirecting stderr:

$ cargo run --example stdio 2>&1 | cat
stdin? true
stdout? false
stderr? false

Minimum Supported Rust Version (MSRV)

This crate currently works on the version of Rust on Debian stable, which is currently Rust 1.48. This policy may change in the future, in minor version releases, so users using a fixed version of Rust should pin to a specific version of this crate.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

"提供检测终端是否存在的支持。 | A Rust library that provides support for detecting whether a terminal is present." expand collapse
Cancel

Releases

No release

Contributors

All

Activities

Load More
can not load any more
1
https://gitee.com/openharmony/third_party_rust_is-terminal.git
git@gitee.com:openharmony/third_party_rust_is-terminal.git
openharmony
third_party_rust_is-terminal
third_party_rust_is-terminal
master

Search