summaryrefslogtreecommitdiff
path: root/vendor/is-terminal
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
committerValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
commit1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch)
tree7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/is-terminal
parent5ecd8cf2cba827454317368b68571df0d13d7842 (diff)
downloadfparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz
fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/is-terminal')
-rw-r--r--vendor/is-terminal/.cargo-checksum.json1
-rw-r--r--vendor/is-terminal/Cargo.toml67
-rw-r--r--vendor/is-terminal/LICENSE-MIT23
-rw-r--r--vendor/is-terminal/LICENSE-MIT-atty23
-rw-r--r--vendor/is-terminal/README.md110
-rw-r--r--vendor/is-terminal/src/lib.rs388
6 files changed, 612 insertions, 0 deletions
diff --git a/vendor/is-terminal/.cargo-checksum.json b/vendor/is-terminal/.cargo-checksum.json
new file mode 100644
index 0000000..b4d0a54
--- /dev/null
+++ b/vendor/is-terminal/.cargo-checksum.json
@@ -0,0 +1 @@
+{"files":{"Cargo.toml":"4bf07c8a80b8632eddd10fb9e9c687c47a47c36729b6aa0349927f6a3df18383","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","LICENSE-MIT-atty":"bab426a663ce3d5bbbcea9cdc300da74e94d76c3c79e46699a953f967a08e533","README.md":"252ffd0e461bf2c22cbedd3b05746cc133a3e9e5426635d6a147e575e8295ec3","src/lib.rs":"e0564f31ae15b98afc4bb0e3e8c60a63698637d2f87df6b0283077734f627af5"},"package":"0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455"} \ No newline at end of file
diff --git a/vendor/is-terminal/Cargo.toml b/vendor/is-terminal/Cargo.toml
new file mode 100644
index 0000000..a1168f2
--- /dev/null
+++ b/vendor/is-terminal/Cargo.toml
@@ -0,0 +1,67 @@
+# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
+#
+# When uploading crates to the registry Cargo will automatically
+# "normalize" Cargo.toml files for maximal compatibility
+# with all versions of Cargo and also rewrite `path` dependencies
+# to registry (e.g., crates.io) dependencies.
+#
+# If you are reading this file be aware that the original Cargo.toml
+# will likely look very different (and much more reasonable).
+# See Cargo.toml.orig for the original contents.
+
+[package]
+edition = "2018"
+rust-version = "1.63"
+name = "is-terminal"
+version = "0.4.10"
+authors = [
+ "softprops <d.tangren@gmail.com>",
+ "Dan Gohman <dev@sunfishcode.online>",
+]
+include = [
+ "src",
+ "build.rs",
+ "Cargo.toml",
+ "COPYRIGHT",
+ "LICENSE*",
+ "/*.md",
+]
+description = "Test whether a given stream is a terminal"
+documentation = "https://docs.rs/is-terminal"
+readme = "README.md"
+keywords = [
+ "terminal",
+ "tty",
+ "isatty",
+]
+categories = ["command-line-interface"]
+license = "MIT"
+repository = "https://github.com/sunfishcode/is-terminal"
+
+[dev-dependencies.atty]
+version = "0.2.14"
+
+[target."cfg(any(unix, target_os = \"wasi\"))".dev-dependencies.libc]
+version = "0.2.110"
+
+[target."cfg(not(any(windows, target_os = \"hermit\", target_os = \"unknown\")))".dependencies.rustix]
+version = "0.38.0"
+features = ["termios"]
+
+[target."cfg(not(any(windows, target_os = \"hermit\", target_os = \"unknown\")))".dev-dependencies.rustix]
+version = "0.38.0"
+features = ["stdio"]
+
+[target."cfg(target_os = \"hermit\")".dependencies.hermit-abi]
+version = "0.3.0"
+
+[target."cfg(windows)".dependencies.windows-sys]
+version = "0.52.0"
+features = [
+ "Win32_Foundation",
+ "Win32_Storage_FileSystem",
+ "Win32_System_Console",
+]
+
+[target."cfg(windows)".dev-dependencies.tempfile]
+version = "3"
diff --git a/vendor/is-terminal/LICENSE-MIT b/vendor/is-terminal/LICENSE-MIT
new file mode 100644
index 0000000..31aa793
--- /dev/null
+++ b/vendor/is-terminal/LICENSE-MIT
@@ -0,0 +1,23 @@
+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.
diff --git a/vendor/is-terminal/LICENSE-MIT-atty b/vendor/is-terminal/LICENSE-MIT-atty
new file mode 100644
index 0000000..b2319d8
--- /dev/null
+++ b/vendor/is-terminal/LICENSE-MIT-atty
@@ -0,0 +1,23 @@
+Portions of this project are derived from atty, which bears the following
+copyright notice and permission notice:
+
+Copyright (c) 2015-2019 Doug Tangren
+
+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.
diff --git a/vendor/is-terminal/README.md b/vendor/is-terminal/README.md
new file mode 100644
index 0000000..045ca9e
--- /dev/null
+++ b/vendor/is-terminal/README.md
@@ -0,0 +1,110 @@
+<div align="center">
+ <h1><code>is-terminal</code></h1>
+
+ <p>
+ <strong>Test whether a given stream is a terminal</strong>
+ </p>
+
+ <p>
+ <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>
+ <a href="https://crates.io/crates/is-terminal"><img src="https://img.shields.io/crates/v/is-terminal.svg" alt="crates.io page" /></a>
+ <a href="https://docs.rs/is-terminal"><img src="https://docs.rs/is-terminal/badge.svg" alt="docs.rs docs" /></a>
+ </p>
+</div>
+
+As of Rust 1.70, most users should use the [`IsTerminal`] trait in the Rust
+standard library instead of this crate.
+
+<hr>
+
+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].
+
+[PR \#51]: https://github.com/softprops/atty/pull/51
+[PR \#54]: https://github.com/softprops/atty/pull/54
+
+## Example
+
+```rust
+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:
+
+```bash
+$ cargo run --example stdio
+stdin? true
+stdout? true
+stderr? true
+```
+
+To test stdin, pipe some text to the program:
+
+```bash
+$ cat | cargo run --example stdio
+stdin? false
+stdout? true
+stderr? true
+```
+
+To test stdout, pipe the program to something:
+
+```bash
+$ cargo run --example stdio | cat
+stdin? true
+stdout? false
+stderr? true
+```
+
+To test stderr, pipe the program to something redirecting stderr:
+
+```bash
+$ 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.63. 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.
+
+[`isatty`]: https://man7.org/linux/man-pages/man3/isatty.3.html
+[the atty crate]: https://crates.io/crates/atty
+[I/O safety]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md
+[Rust on Debian stable]: https://packages.debian.org/stable/rust/rustc
+[`IsTerminal`]: https://doc.rust-lang.org/stable/std/io/trait.IsTerminal.html
diff --git a/vendor/is-terminal/src/lib.rs b/vendor/is-terminal/src/lib.rs
new file mode 100644
index 0000000..56810b7
--- /dev/null
+++ b/vendor/is-terminal/src/lib.rs
@@ -0,0 +1,388 @@
+//! 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.
+//!
+//! # Example
+//!
+//! ```rust
+//! use is_terminal::IsTerminal;
+//!
+//! if std::io::stdout().is_terminal() {
+//! println!("stdout is a terminal")
+//! }
+//! ```
+//!
+//! [`isatty`]: https://man7.org/linux/man-pages/man3/isatty.3.html
+
+#![cfg_attr(unix, no_std)]
+
+#[cfg(not(any(windows, target_os = "hermit", target_os = "unknown")))]
+use rustix::fd::AsFd;
+#[cfg(target_os = "hermit")]
+use std::os::hermit::io::AsFd;
+#[cfg(windows)]
+use std::os::windows::io::{AsHandle, AsRawHandle, BorrowedHandle};
+#[cfg(windows)]
+use windows_sys::Win32::Foundation::HANDLE;
+
+/// Extension trait to check whether something is a terminal.
+pub trait IsTerminal {
+ /// Returns true if this is a terminal.
+ ///
+ /// # Example
+ ///
+ /// ```
+ /// use is_terminal::IsTerminal;
+ ///
+ /// if std::io::stdout().is_terminal() {
+ /// println!("stdout is a terminal")
+ /// }
+ /// ```
+ fn is_terminal(&self) -> bool;
+}
+
+/// Returns `true` if `this` is a terminal.
+///
+/// This is equivalent to calling `this.is_terminal()` and exists only as a
+/// convenience to calling the trait method [`IsTerminal::is_terminal`]
+/// without importing the trait.
+///
+/// # Example
+///
+/// ```
+/// if is_terminal::is_terminal(&std::io::stdout()) {
+/// println!("stdout is a terminal")
+/// }
+/// ```
+pub fn is_terminal<T: IsTerminal>(this: T) -> bool {
+ this.is_terminal()
+}
+
+#[cfg(not(any(windows, target_os = "unknown")))]
+impl<Stream: AsFd> IsTerminal for Stream {
+ #[inline]
+ fn is_terminal(&self) -> bool {
+ #[cfg(any(unix, target_os = "wasi"))]
+ {
+ rustix::termios::isatty(self)
+ }
+
+ #[cfg(target_os = "hermit")]
+ {
+ use std::os::hermit::io::AsRawFd;
+ hermit_abi::isatty(self.as_fd().as_fd().as_raw_fd())
+ }
+ }
+}
+
+#[cfg(windows)]
+impl<Stream: AsHandle> IsTerminal for Stream {
+ #[inline]
+ fn is_terminal(&self) -> bool {
+ handle_is_console(self.as_handle())
+ }
+}
+
+// The Windows implementation here is copied from `handle_is_console` in
+// std/src/sys/windows/io.rs in Rust at revision
+// d7b0bcb20f2f7d5f3ea3489d56ece630147e98f5.
+
+#[cfg(windows)]
+fn handle_is_console(handle: BorrowedHandle<'_>) -> bool {
+ use windows_sys::Win32::System::Console::{
+ GetConsoleMode, GetStdHandle, STD_ERROR_HANDLE, STD_INPUT_HANDLE, STD_OUTPUT_HANDLE,
+ };
+
+ let handle = handle.as_raw_handle();
+
+ unsafe {
+ // A null handle means the process has no console.
+ if handle.is_null() {
+ return false;
+ }
+
+ let mut out = 0;
+ if GetConsoleMode(handle as HANDLE, &mut out) != 0 {
+ // False positives aren't possible. If we got a console then we definitely have a console.
+ return true;
+ }
+
+ // At this point, we *could* have a false negative. We can determine that this is a true
+ // negative if we can detect the presence of a console on any of the standard I/O streams. If
+ // another stream has a console, then we know we're in a Windows console and can therefore
+ // trust the negative.
+ for std_handle in [STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, STD_ERROR_HANDLE] {
+ let std_handle = GetStdHandle(std_handle);
+ if std_handle != 0
+ && std_handle != handle as HANDLE
+ && GetConsoleMode(std_handle, &mut out) != 0
+ {
+ return false;
+ }
+ }
+
+ // Otherwise, we fall back to an msys hack to see if we can detect the presence of a pty.
+ msys_tty_on(handle as HANDLE)
+ }
+}
+
+/// Returns true if there is an MSYS tty on the given handle.
+///
+/// This incoproates d7b0bcb20f2f7d5f3ea3489d56ece630147e98f5
+#[cfg(windows)]
+unsafe fn msys_tty_on(handle: HANDLE) -> bool {
+ use std::ffi::c_void;
+ use windows_sys::Win32::{
+ Foundation::MAX_PATH,
+ Storage::FileSystem::{
+ FileNameInfo, GetFileInformationByHandleEx, GetFileType, FILE_TYPE_PIPE,
+ },
+ };
+
+ // Early return if the handle is not a pipe.
+ if GetFileType(handle) != FILE_TYPE_PIPE {
+ return false;
+ }
+
+ /// Mirrors windows_sys::Win32::Storage::FileSystem::FILE_NAME_INFO, giving
+ /// it a fixed length that we can stack allocate
+ #[repr(C)]
+ #[allow(non_snake_case)]
+ struct FILE_NAME_INFO {
+ FileNameLength: u32,
+ FileName: [u16; MAX_PATH as usize],
+ }
+ let mut name_info = FILE_NAME_INFO {
+ FileNameLength: 0,
+ FileName: [0; MAX_PATH as usize],
+ };
+ // Safety: buffer length is fixed.
+ let res = GetFileInformationByHandleEx(
+ handle,
+ FileNameInfo,
+ &mut name_info as *mut _ as *mut c_void,
+ std::mem::size_of::<FILE_NAME_INFO>() as u32,
+ );
+ if res == 0 {
+ return false;
+ }
+
+ // Use `get` because `FileNameLength` can be out of range.
+ let s = match name_info
+ .FileName
+ .get(..name_info.FileNameLength as usize / 2)
+ {
+ None => return false,
+ Some(s) => s,
+ };
+ let name = String::from_utf16_lossy(s);
+ // Get the file name only.
+ let name = name.rsplit('\\').next().unwrap_or(&name);
+ // This checks whether 'pty' exists in the file name, which indicates that
+ // a pseudo-terminal is attached. To mitigate against false positives
+ // (e.g., an actual file name that contains 'pty'), we also require that
+ // the file name begins with either the strings 'msys-' or 'cygwin-'.)
+ let is_msys = name.starts_with("msys-") || name.starts_with("cygwin-");
+ let is_pty = name.contains("-pty");
+ is_msys && is_pty
+}
+
+#[cfg(target_os = "unknown")]
+impl IsTerminal for std::io::Stdin {
+ #[inline]
+ fn is_terminal(&self) -> bool {
+ false
+ }
+}
+
+#[cfg(target_os = "unknown")]
+impl IsTerminal for std::io::Stdout {
+ #[inline]
+ fn is_terminal(&self) -> bool {
+ false
+ }
+}
+
+#[cfg(target_os = "unknown")]
+impl IsTerminal for std::io::Stderr {
+ #[inline]
+ fn is_terminal(&self) -> bool {
+ false
+ }
+}
+
+#[cfg(target_os = "unknown")]
+impl<'a> IsTerminal for std::io::StdinLock<'a> {
+ #[inline]
+ fn is_terminal(&self) -> bool {
+ false
+ }
+}
+
+#[cfg(target_os = "unknown")]
+impl<'a> IsTerminal for std::io::StdoutLock<'a> {
+ #[inline]
+ fn is_terminal(&self) -> bool {
+ false
+ }
+}
+
+#[cfg(target_os = "unknown")]
+impl<'a> IsTerminal for std::io::StderrLock<'a> {
+ #[inline]
+ fn is_terminal(&self) -> bool {
+ false
+ }
+}
+
+#[cfg(target_os = "unknown")]
+impl<'a> IsTerminal for std::fs::File {
+ #[inline]
+ fn is_terminal(&self) -> bool {
+ false
+ }
+}
+
+#[cfg(target_os = "unknown")]
+impl IsTerminal for std::process::ChildStdin {
+ #[inline]
+ fn is_terminal(&self) -> bool {
+ false
+ }
+}
+
+#[cfg(target_os = "unknown")]
+impl IsTerminal for std::process::ChildStdout {
+ #[inline]
+ fn is_terminal(&self) -> bool {
+ false
+ }
+}
+
+#[cfg(target_os = "unknown")]
+impl IsTerminal for std::process::ChildStderr {
+ #[inline]
+ fn is_terminal(&self) -> bool {
+ false
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ #[cfg(not(target_os = "unknown"))]
+ use super::IsTerminal;
+
+ #[test]
+ #[cfg(windows)]
+ fn stdin() {
+ assert_eq!(
+ atty::is(atty::Stream::Stdin),
+ std::io::stdin().is_terminal()
+ )
+ }
+
+ #[test]
+ #[cfg(windows)]
+ fn stdout() {
+ assert_eq!(
+ atty::is(atty::Stream::Stdout),
+ std::io::stdout().is_terminal()
+ )
+ }
+
+ #[test]
+ #[cfg(windows)]
+ fn stderr() {
+ assert_eq!(
+ atty::is(atty::Stream::Stderr),
+ std::io::stderr().is_terminal()
+ )
+ }
+
+ #[test]
+ #[cfg(any(unix, target_os = "wasi"))]
+ fn stdin() {
+ assert_eq!(
+ atty::is(atty::Stream::Stdin),
+ rustix::stdio::stdin().is_terminal()
+ )
+ }
+
+ #[test]
+ #[cfg(any(unix, target_os = "wasi"))]
+ fn stdout() {
+ assert_eq!(
+ atty::is(atty::Stream::Stdout),
+ rustix::stdio::stdout().is_terminal()
+ )
+ }
+
+ #[test]
+ #[cfg(any(unix, target_os = "wasi"))]
+ fn stderr() {
+ assert_eq!(
+ atty::is(atty::Stream::Stderr),
+ rustix::stdio::stderr().is_terminal()
+ )
+ }
+
+ #[test]
+ #[cfg(any(unix, target_os = "wasi"))]
+ fn stdin_vs_libc() {
+ unsafe {
+ assert_eq!(
+ libc::isatty(libc::STDIN_FILENO) != 0,
+ rustix::stdio::stdin().is_terminal()
+ )
+ }
+ }
+
+ #[test]
+ #[cfg(any(unix, target_os = "wasi"))]
+ fn stdout_vs_libc() {
+ unsafe {
+ assert_eq!(
+ libc::isatty(libc::STDOUT_FILENO) != 0,
+ rustix::stdio::stdout().is_terminal()
+ )
+ }
+ }
+
+ #[test]
+ #[cfg(any(unix, target_os = "wasi"))]
+ fn stderr_vs_libc() {
+ unsafe {
+ assert_eq!(
+ libc::isatty(libc::STDERR_FILENO) != 0,
+ rustix::stdio::stderr().is_terminal()
+ )
+ }
+ }
+
+ // Verify that the msys_tty_on function works with long path.
+ #[test]
+ #[cfg(windows)]
+ fn msys_tty_on_path_length() {
+ use std::{fs::File, os::windows::io::AsRawHandle};
+ use windows_sys::Win32::Foundation::MAX_PATH;
+
+ let dir = tempfile::tempdir().expect("Unable to create temporary directory");
+ let file_path = dir.path().join("ten_chars_".repeat(25));
+ // Ensure that the path is longer than MAX_PATH.
+ assert!(file_path.to_string_lossy().len() > MAX_PATH as usize);
+ let file = File::create(file_path).expect("Unable to create file");
+
+ assert!(!unsafe { crate::msys_tty_on(file.as_raw_handle() as isize) });
+ }
+}