Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
This commit is contained in:
1
vendor/supports-color/.cargo-checksum.json
vendored
Normal file
1
vendor/supports-color/.cargo-checksum.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"files":{"CHANGELOG.md":"6f19ad79d30989fef7f129fcb62c83122ab7f24074fe0d62bf5bbc476929b8be","Cargo.toml":"b7652561cdb25cc919dd76f539ab368d2e8e2aa6bc11d4be62697d83511d40f5","LICENSE":"02872c3ff23e11da5a9b3289df11b581be36b4956bfb7cfdc3d8043f92d64794","Makefile.toml":"c8e1149898035a2ca4eaffc8cc7e9f89bd1b2b4f64b8dd6fd60f1b95e6cc8ebf","README.md":"36041f7eff9cfd2633e3b60d3d1936c94f10e92f84bd5b6fc0ab14b850430680","cliff.toml":"48cfc4dcbe9548c647843ca72deb0b76328454b7431099760d2cb2c57db1f10d","src/lib.rs":"41ef2eec9ae26a11e149b6130f348aa3f817e328cb551b499ddc573e750ba1b6","tests/cached.rs":"ae0c3d02b2f45d7745304ffd34a6740e5aa57c74d550b5a1943c82d96a54cdab"},"package":"d6398cde53adc3c4557306a96ce67b302968513830a77a95b2b17305d9719a89"}
|
93
vendor/supports-color/CHANGELOG.md
vendored
Normal file
93
vendor/supports-color/CHANGELOG.md
vendored
Normal file
@ -0,0 +1,93 @@
|
||||
# `supports-color` Release Changelog
|
||||
|
||||
<a name="2.1.0"></a>
|
||||
## 2.1.0 (2023-09-20)
|
||||
|
||||
### Features
|
||||
|
||||
* **ignore_is_terminal:** Allow the is_terminal check to be overridden by environment variable. (#13) ([ff0a31a6](https://github.com/zkat/supports-color/commit/ff0a31a672da89a48ad1978220184b91218fde32))
|
||||
* **truecolor:** improve check for truecolor (#14) ([736c044a](https://github.com/zkat/supports-color/commit/736c044a9aa36e259fef25cd790c466f1bf7b011))
|
||||
|
||||
<a name="2.0.0"></a>
|
||||
## 2.0.0 (2022-12-15)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **deps:** Replace atty with is_terminal (#10) ([edf565e5](https://github.com/zkat/supports-color/commit/edf565e553a2ad8b429a0b54ecec4128b6430e2b))
|
||||
* **BREAKING CHANGE**: Exported stream types are no longer atty's getting re-exported.
|
||||
|
||||
<a name="1.3.1"></a>
|
||||
## 1.3.1 (2022-11-05)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **docs:** Update README example for accuracy (#7) ([88a56df7](https://github.com/zkat/supports-color/commit/88a56df7d3143cd71b1f5ad88b0f65ff6ddce8eb))
|
||||
* **alloc:** stop allocating unnecessary Strings (#8) ([606262f7](https://github.com/zkat/supports-color/commit/606262f7c1fd117610b582fa28ae0acf60341164))
|
||||
|
||||
<a name="1.3.0"></a>
|
||||
## 1.3.0 (2021-10-03)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **clicolor:** Ignore unit tests on GH action and change order of CLICOLOR check (#5) ([370e8188](https://github.com/zkat/supports-color/commit/370e81885bf683287cdb2f639b59b86425d90e9c))
|
||||
|
||||
### Features
|
||||
|
||||
* **msrv:** Reduce MSRV from 1.54 to 1.42 (#6) ([a33337a6](https://github.com/zkat/supports-color/commit/a33337a653d3bfe71007947cd3ee57a787dcce64))
|
||||
|
||||
<a name="1.2.0"></a>
|
||||
## 1.2.0 (2021-10-01)
|
||||
|
||||
### Features
|
||||
|
||||
* **clicolor:** Add CLICOLOR support (#4) ([71b0ff30](https://github.com/zkat/supports-color/commit/71b0ff30be9a9aa78d2d0197957d815fc5d1a357))
|
||||
|
||||
<a name="1.1.1"></a>
|
||||
## 1.1.1 (2021-09-22)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **deps:** bump is_ci because of missing api ([31d57374](https://github.com/zkat/supports-color/commit/31d5737420ae2a587e63f4ce03ad3099dad25289))
|
||||
|
||||
<a name="1.1.0"></a>
|
||||
## 1.1.0 (2021-09-22)
|
||||
|
||||
### Features
|
||||
|
||||
* **api:** Add cached version of supports_color::on (#1) ([2cf2b76f](https://github.com/zkat/supports-color/commit/2cf2b76f585d591acda45c28bffeeba28d030bfd))
|
||||
|
||||
<a name="1.0.4"></a>
|
||||
## 1.0.4 (2021-09-22)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **deps:** remove dependencies on regex and lazy-static too ([366f5b92](https://github.com/zkat/supports-color/commit/366f5b92c8c806572f74adc91e8716e434a95efb))
|
||||
|
||||
<a name="1.0.3"></a>
|
||||
## 1.0.3 (2021-09-22)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **deps:** switch to much more lightweight is_ci ([d481c017](https://github.com/zkat/supports-color/commit/d481c01754ebaefa7bcaf154b8a7c7d8d25bebb5))
|
||||
|
||||
<a name="1.0.2"></a>
|
||||
## 1.0.2 (2021-09-11)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **detection:** messed up logic on windows and forgot no_color. oops ([fbecf72f](https://github.com/zkat/supports-color/commit/fbecf72f6331ddc08de625861d9bece0370b07c3))
|
||||
|
||||
<a name="1.0.1"></a>
|
||||
## 1.0.1 (2021-09-11)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **api:** forgot to export atty::Stream, and example was totally wrong ([a9eef66f](https://github.com/zkat/supports-color/commit/a9eef66f5fa6b75b14bbb4d860f24dba9dcf5724))
|
||||
|
||||
<a name="1.0.0"></a>
|
||||
## 1.0.0 (2021-09-11)
|
||||
|
||||
### Features
|
||||
|
||||
* **api:** initial commit ([fbb068d0](https://github.com/zkat/supports-color/commit/fbb068d070687eac0ecbef23015c07cd025ce161))
|
||||
|
28
vendor/supports-color/Cargo.toml
vendored
Normal file
28
vendor/supports-color/Cargo.toml
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
# 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"
|
||||
name = "supports-color"
|
||||
version = "2.1.0"
|
||||
authors = ["Kat Marchán <kzm@zkat.tech>"]
|
||||
description = "Detects whether a terminal supports color, and gives details about that support."
|
||||
documentation = "https://docs.rs/supports-color"
|
||||
readme = "README.md"
|
||||
categories = ["terminal"]
|
||||
license = "Apache-2.0"
|
||||
repository = "https://github.com/zkat/supports-color"
|
||||
|
||||
[dependencies.is-terminal]
|
||||
version = "0.4.0"
|
||||
|
||||
[dependencies.is_ci]
|
||||
version = "1.1.1"
|
229
vendor/supports-color/LICENSE
vendored
Normal file
229
vendor/supports-color/LICENSE
vendored
Normal file
@ -0,0 +1,229 @@
|
||||
Apache License
|
||||
|
||||
Version 2.0, January 2004
|
||||
|
||||
http://www.apache.org/licenses/ TERMS
|
||||
AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
|
||||
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, and
|
||||
distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
|
||||
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
||||
owner that is granting the License.
|
||||
|
||||
|
||||
|
||||
"Legal Entity" shall mean the
|
||||
union of the acting entity and all other entities that control, are controlled
|
||||
by, or are under common control with that entity. For the purposes of this
|
||||
definition, "control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or otherwise, or (ii)
|
||||
ownership of fifty percent (50%) or more of the outstanding shares, or (iii)
|
||||
beneficial ownership of such entity.
|
||||
|
||||
|
||||
|
||||
"You" (or "Your") shall mean
|
||||
an individual or Legal Entity exercising permissions granted by this License.
|
||||
|
||||
|
||||
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation source, and
|
||||
configuration files.
|
||||
|
||||
|
||||
|
||||
"Object" form shall mean any form resulting
|
||||
from mechanical transformation or translation of a Source form, including but not
|
||||
limited to compiled object code, generated documentation, and conversions to
|
||||
other media types.
|
||||
|
||||
|
||||
|
||||
"Work" shall mean the work of authorship,
|
||||
whether in Source or Object form, made available under the License, as indicated
|
||||
by a copyright notice that is included in or attached to the work (an example is
|
||||
provided in the Appendix below).
|
||||
|
||||
|
||||
|
||||
"Derivative Works" shall mean any
|
||||
work, whether in Source or Object form, that is based on (or derived from) the
|
||||
Work and for which the editorial revisions, annotations, elaborations, or other
|
||||
modifications represent, as a whole, an original work of authorship. For the
|
||||
purposes of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of, the Work
|
||||
and Derivative Works thereof.
|
||||
|
||||
|
||||
|
||||
"Contribution" shall mean any work
|
||||
of authorship, including the original version of the Work and any modifications
|
||||
or additions to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner or by an
|
||||
individual or Legal Entity authorized to submit on behalf of the copyright owner.
|
||||
For the purposes of this definition, "submitted" means any form of electronic,
|
||||
verbal, or written communication sent to the Licensor or its representatives,
|
||||
including but not limited to communication on electronic mailing lists, source
|
||||
code control systems, and issue tracking systems that are managed by, or on
|
||||
behalf of, the Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise designated in
|
||||
writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
|
||||
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of
|
||||
whom a Contribution has been received by Licensor and subsequently incorporated
|
||||
within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and
|
||||
conditions of this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license
|
||||
to reproduce, prepare Derivative Works of, publicly display, publicly perform,
|
||||
sublicense, and distribute the Work and such Derivative Works in Source or Object
|
||||
form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of this
|
||||
License, each Contributor hereby grants to You a perpetual, worldwide,
|
||||
non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
|
||||
section) patent license to make, have made, use, offer to sell, sell, import, and
|
||||
otherwise transfer the Work, where such license applies only to those patent
|
||||
claims licensable by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s) with the Work to
|
||||
which such Contribution(s) was submitted. If You institute patent litigation
|
||||
against any entity (including a cross-claim or counterclaim in a lawsuit)
|
||||
alleging that the Work or a Contribution incorporated within the Work constitutes
|
||||
direct or contributory patent infringement, then any patent licenses granted to
|
||||
You under this License for that Work shall terminate as of the date such
|
||||
litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute
|
||||
copies of the Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You meet the following
|
||||
conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any
|
||||
modified files to carry prominent notices stating that You changed the files;
|
||||
and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works that
|
||||
You distribute, all copyright, patent, trademark, and attribution notices from
|
||||
the Source form of the Work, excluding those notices that do not pertain to any
|
||||
part of the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text
|
||||
file as part of its distribution, then any Derivative Works that You distribute
|
||||
must include a readable copy of the attribution notices contained within such
|
||||
NOTICE file, excluding those notices that do not pertain to any part of the
|
||||
Derivative Works, in at least one of the following places: within a NOTICE text
|
||||
file distributed as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or, within a display
|
||||
generated by the Derivative Works, if and wherever such third-party notices
|
||||
normally appear. The contents of the NOTICE file are for informational purposes
|
||||
only and do not modify the License. You may add Your own attribution notices
|
||||
within Derivative Works that You distribute, alongside or as an addendum to the
|
||||
NOTICE text from the Work, provided that such additional attribution notices
|
||||
cannot be construed as modifying the License.
|
||||
|
||||
You may add Your own
|
||||
copyright statement to Your modifications and may provide additional or different
|
||||
license terms and conditions for use, reproduction, or distribution of Your
|
||||
modifications, or for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with the conditions
|
||||
stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly
|
||||
state otherwise, any Contribution intentionally submitted for inclusion in the
|
||||
Work by You to the Licensor shall be under the terms and conditions of this
|
||||
License, without any additional terms or conditions. Notwithstanding the above,
|
||||
nothing herein shall supersede or modify the terms of any separate license
|
||||
agreement you may have executed with Licensor regarding such Contributions.
|
||||
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade names,
|
||||
trademarks, service marks, or product names of the Licensor, except as required
|
||||
for reasonable and customary use in describing the origin of the Work and
|
||||
reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless
|
||||
required by applicable law or agreed to in writing, Licensor provides the Work
|
||||
(and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT
|
||||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including,
|
||||
without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
|
||||
MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible
|
||||
for determining the appropriateness of using or redistributing the Work and
|
||||
assume any risks associated with Your exercise of permissions under this
|
||||
License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise, unless required
|
||||
by applicable law (such as deliberate and grossly negligent acts) or agreed to in
|
||||
writing, shall any Contributor be liable to You for damages, including any
|
||||
direct, indirect, special, incidental, or consequential damages of any character
|
||||
arising as a result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill, work stoppage,
|
||||
computer failure or malfunction, or any and all other commercial damages or
|
||||
losses), even if such Contributor has been advised of the possibility of such
|
||||
damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer, and charge a fee
|
||||
for, acceptance of support, warranty, indemnity, or other liability obligations
|
||||
and/or rights consistent with this License. However, in accepting such
|
||||
obligations, You may act only on Your own behalf and on Your sole responsibility,
|
||||
not on behalf of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability incurred by, or
|
||||
claims asserted against, such Contributor by reason of your accepting any such
|
||||
warranty or additional liability. END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to
|
||||
apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work,
|
||||
attach the following boilerplate notice, with the fields enclosed by brackets
|
||||
"[]" replaced with your own identifying information. (Don't include the
|
||||
brackets!) The text should be enclosed in the appropriate comment syntax for the
|
||||
file format. We also recommend that a file or class name and description of
|
||||
purpose be included on the same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] Kat
|
||||
Marchán
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
||||
you may
|
||||
not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy
|
||||
of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by
|
||||
applicable law or agreed to in writing, software
|
||||
|
||||
distributed under the License
|
||||
is distributed on an "AS IS" BASIS,
|
||||
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied.
|
||||
|
||||
See the License for the specific language
|
||||
governing permissions and
|
||||
|
||||
limitations under the License.
|
11
vendor/supports-color/Makefile.toml
vendored
Normal file
11
vendor/supports-color/Makefile.toml
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
[tasks.changelog]
|
||||
workspace=false
|
||||
install_crate="git-cliff"
|
||||
command = "git-cliff"
|
||||
args = ["--prepend", "CHANGELOG.md", "-u", "--tag", "${@}"]
|
||||
|
||||
[tasks.release]
|
||||
workspace=false
|
||||
install_crate="cargo-release"
|
||||
command = "cargo"
|
||||
args = ["release", "--workspace", "${@}"]
|
23
vendor/supports-color/README.md
vendored
Normal file
23
vendor/supports-color/README.md
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
Detects whether a terminal supports color, and gives details about that
|
||||
support. It takes into account the `NO_COLOR` environment variable.
|
||||
|
||||
This crate is a Rust port of [@sindresorhus](https://github.com/sindresorhus)'
|
||||
[NPM package by the same name](https://npm.im/supports-color).
|
||||
|
||||
## Example
|
||||
|
||||
```rust
|
||||
use supports_color::Stream;
|
||||
|
||||
if let Some(support) = supports_color::on(Stream::Stdout) {
|
||||
if support.has_16m {
|
||||
println!("16 million (RGB) colors are supported");
|
||||
} else if support.has_256 {
|
||||
println!("256 colors are supported.");
|
||||
} else if support.has_basic {
|
||||
println!("Only basic ANSI colors are supported.");
|
||||
}
|
||||
} else {
|
||||
println!("No color support.");
|
||||
}
|
||||
```
|
62
vendor/supports-color/cliff.toml
vendored
Normal file
62
vendor/supports-color/cliff.toml
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
# configuration file for git-cliff (0.1.0)
|
||||
|
||||
[changelog]
|
||||
# changelog header
|
||||
header = """
|
||||
# `supports-color` Release Changelog
|
||||
|
||||
"""
|
||||
|
||||
# template for the changelog body
|
||||
# https://tera.netlify.app/docs/#introduction
|
||||
body = """
|
||||
{% if version %}\
|
||||
<a name="{{ version }}"></a>
|
||||
## {{ version | replace(from="v", to="") }} ({{ timestamp | date(format="%Y-%m-%d") }})
|
||||
{% else %}\
|
||||
## Unreleased
|
||||
{% endif %}\
|
||||
{% for group, commits in commits | filter(attribute="scope") | group_by(attribute="group") %}
|
||||
### {{ group | upper_first }}
|
||||
{% for commit in commits %}
|
||||
{% if commit.scope %}\
|
||||
* **{{ commit.scope }}:** {{ commit.message }} ([{{ commit.id | truncate(length=8, end="") }}](https://github.com/zkat/supports-color/commit/{{ commit.id }}))
|
||||
{%- if commit.breaking %}
|
||||
* **BREAKING CHANGE**: {{ commit.breaking_description }}
|
||||
{%- endif %}\
|
||||
{% endif %}\
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
"""
|
||||
|
||||
# remove the leading and trailing whitespace from the template
|
||||
trim = false
|
||||
|
||||
# changelog footer
|
||||
# footer = """
|
||||
# <!-- generated by git-cliff -->
|
||||
# """
|
||||
|
||||
[git]
|
||||
# allow only conventional commits
|
||||
# https://www.conventionalcommits.org
|
||||
conventional_commits = true
|
||||
# regex for parsing and grouping commits
|
||||
commit_parsers = [
|
||||
{ message = "^feat*", group = "Features"},
|
||||
{ message = "^fix*", group = "Bug Fixes"},
|
||||
{ message = "^doc*", group = "Documentation"},
|
||||
{ message = "^perf*", group = "Performance"},
|
||||
{ message = "^refactor*", group = "Refactor"},
|
||||
{ message = "^style*", group = "Styling"},
|
||||
{ message = "^test*", group = "Testing"},
|
||||
{ message = "^chore\\(release\\): prepare for*", skip = true},
|
||||
{ message = "^chore*", group = "Miscellaneous Tasks"},
|
||||
{ body = ".*security", group = "Security"},
|
||||
]
|
||||
# filter out the commits that are not matched by commit parsers
|
||||
filter_commits = false
|
||||
# glob pattern for matching git tags
|
||||
# tag_pattern = "[0-9]*"
|
||||
# regex for skipping tags
|
||||
# skip_tags = "v0.1.0-beta.1"
|
263
vendor/supports-color/src/lib.rs
vendored
Normal file
263
vendor/supports-color/src/lib.rs
vendored
Normal file
@ -0,0 +1,263 @@
|
||||
//! Detects whether a terminal supports color, and gives details about that
|
||||
//! support. It takes into account the `NO_COLOR` environment variable.
|
||||
//!
|
||||
//! This crate is a Rust port of [@sindresorhus](https://github.com/sindresorhus)'
|
||||
//! [NPM package by the same name](https://npm.im/supports-color).
|
||||
//!
|
||||
//! ## Example
|
||||
//!
|
||||
//! ```rust
|
||||
//! use supports_color::Stream;
|
||||
//!
|
||||
//! if let Some(support) = supports_color::on(Stream::Stdout) {
|
||||
//! if support.has_16m {
|
||||
//! println!("16 million (RGB) colors are supported");
|
||||
//! } else if support.has_256 {
|
||||
//! println!("256-bit colors are supported.");
|
||||
//! } else if support.has_basic {
|
||||
//! println!("Only basic ANSI colors are supported.");
|
||||
//! }
|
||||
//! } else {
|
||||
//! println!("No color support.");
|
||||
//! }
|
||||
//! ```
|
||||
#![allow(clippy::bool_to_int_with_if)]
|
||||
|
||||
use std::cell::UnsafeCell;
|
||||
use std::env;
|
||||
use std::sync::Once;
|
||||
|
||||
/// possible stream sources
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum Stream {
|
||||
Stdout,
|
||||
Stderr,
|
||||
}
|
||||
|
||||
fn env_force_color() -> usize {
|
||||
if let Ok(force) = env::var("FORCE_COLOR") {
|
||||
match force.as_ref() {
|
||||
"true" | "" => 1,
|
||||
"false" => 0,
|
||||
f => std::cmp::min(f.parse().unwrap_or(1), 3),
|
||||
}
|
||||
} else if let Ok(cli_clr_force) = env::var("CLICOLOR_FORCE") {
|
||||
if cli_clr_force != "0" {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
fn env_no_color() -> bool {
|
||||
match as_str(&env::var("NO_COLOR")) {
|
||||
Ok("0") | Err(_) => false,
|
||||
Ok(_) => true,
|
||||
}
|
||||
}
|
||||
|
||||
// same as Option::as_deref
|
||||
fn as_str<E>(option: &Result<String, E>) -> Result<&str, &E> {
|
||||
match option {
|
||||
Ok(inner) => Ok(inner),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
fn translate_level(level: usize) -> Option<ColorLevel> {
|
||||
if level == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(ColorLevel {
|
||||
level,
|
||||
has_basic: true,
|
||||
has_256: level >= 2,
|
||||
has_16m: level >= 3,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn is_a_tty(stream: Stream) -> bool {
|
||||
use is_terminal::*;
|
||||
match stream {
|
||||
Stream::Stdout => std::io::stdout().is_terminal(),
|
||||
Stream::Stderr => std::io::stderr().is_terminal(),
|
||||
}
|
||||
}
|
||||
|
||||
fn supports_color(stream: Stream) -> usize {
|
||||
let force_color = env_force_color();
|
||||
if force_color > 0 {
|
||||
force_color
|
||||
} else if env_no_color()
|
||||
|| as_str(&env::var("TERM")) == Ok("dumb")
|
||||
|| !(is_a_tty(stream) || env::var("IGNORE_IS_TERMINAL").map_or(false, |v| v != "0"))
|
||||
{
|
||||
0
|
||||
} else if env::var("COLORTERM").map(|colorterm| check_colorterm_16m(&colorterm)) == Ok(true)
|
||||
|| env::var("TERM").map(|term| check_term_16m(&term)) == Ok(true)
|
||||
|| as_str(&env::var("TERM_PROGRAM")) == Ok("iTerm.app")
|
||||
{
|
||||
3
|
||||
} else if as_str(&env::var("TERM_PROGRAM")) == Ok("Apple_Terminal")
|
||||
|| env::var("TERM").map(|term| check_256_color(&term)) == Ok(true)
|
||||
{
|
||||
2
|
||||
} else if env::var("COLORTERM").is_ok()
|
||||
|| env::var("TERM").map(|term| check_ansi_color(&term)) == Ok(true)
|
||||
|| env::consts::OS == "windows"
|
||||
|| env::var("CLICOLOR").map_or(false, |v| v != "0")
|
||||
|| is_ci::uncached()
|
||||
{
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
fn check_ansi_color(term: &str) -> bool {
|
||||
term.starts_with("screen")
|
||||
|| term.starts_with("xterm")
|
||||
|| term.starts_with("vt100")
|
||||
|| term.starts_with("vt220")
|
||||
|| term.starts_with("rxvt")
|
||||
|| term.contains("color")
|
||||
|| term.contains("ansi")
|
||||
|| term.contains("cygwin")
|
||||
|| term.contains("linux")
|
||||
}
|
||||
|
||||
fn check_colorterm_16m(colorterm: &str) -> bool {
|
||||
colorterm == "truecolor" || colorterm == "24bit"
|
||||
}
|
||||
|
||||
fn check_term_16m(term: &str) -> bool {
|
||||
term.ends_with("direct") || term.ends_with("truecolor")
|
||||
}
|
||||
|
||||
fn check_256_color(term: &str) -> bool {
|
||||
term.ends_with("256") || term.ends_with("256color")
|
||||
}
|
||||
|
||||
/**
|
||||
Returns a [ColorLevel] if a [Stream] supports terminal colors.
|
||||
*/
|
||||
pub fn on(stream: Stream) -> Option<ColorLevel> {
|
||||
translate_level(supports_color(stream))
|
||||
}
|
||||
|
||||
struct CacheCell(UnsafeCell<Option<ColorLevel>>);
|
||||
|
||||
unsafe impl Sync for CacheCell {}
|
||||
|
||||
static INIT: [Once; 2] = [Once::new(), Once::new()];
|
||||
static ON_CACHE: [CacheCell; 2] = [
|
||||
CacheCell(UnsafeCell::new(None)),
|
||||
CacheCell(UnsafeCell::new(None)),
|
||||
];
|
||||
|
||||
macro_rules! assert_stream_in_bounds {
|
||||
($($variant:ident)*) => {
|
||||
$(
|
||||
const _: () = [(); 2][Stream::$variant as usize];
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
// Compile-time assertion that the below indexing will never panic
|
||||
assert_stream_in_bounds!(Stdout Stderr);
|
||||
|
||||
/**
|
||||
Returns a [ColorLevel] if a [Stream] supports terminal colors, caching the result to
|
||||
be returned from then on.
|
||||
|
||||
If you expect your environment to change between calls, use [`on`]
|
||||
*/
|
||||
pub fn on_cached(stream: Stream) -> Option<ColorLevel> {
|
||||
let stream_index = stream as usize;
|
||||
INIT[stream_index].call_once(|| unsafe {
|
||||
*ON_CACHE[stream_index].0.get() = translate_level(supports_color(stream));
|
||||
});
|
||||
|
||||
unsafe { *ON_CACHE[stream_index].0.get() }
|
||||
}
|
||||
|
||||
/**
|
||||
Color level support details.
|
||||
|
||||
This type is returned from [on]. See documentation for its fields for more details.
|
||||
*/
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
|
||||
pub struct ColorLevel {
|
||||
level: usize,
|
||||
/// Basic ANSI colors are supported.
|
||||
pub has_basic: bool,
|
||||
/// 256-bit colors are supported.
|
||||
pub has_256: bool,
|
||||
/// 16 million (RGB) colors are supported.
|
||||
pub has_16m: bool,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::sync::Mutex;
|
||||
|
||||
use super::*;
|
||||
|
||||
// needed to prevent race conditions when mutating the environment
|
||||
static TEST_LOCK: Mutex<()> = Mutex::new(());
|
||||
|
||||
fn set_up() {
|
||||
// clears process env variable
|
||||
env::vars().for_each(|(k, _v)| env::remove_var(k));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg_attr(miri, ignore)]
|
||||
fn test_empty_env() {
|
||||
let _test_guard = TEST_LOCK.lock().unwrap();
|
||||
set_up();
|
||||
|
||||
assert_eq!(on(Stream::Stdout), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg_attr(miri, ignore)]
|
||||
fn test_clicolor_ansi() {
|
||||
let _test_guard = TEST_LOCK.lock().unwrap();
|
||||
set_up();
|
||||
|
||||
env::set_var("IGNORE_IS_TERMINAL", "1");
|
||||
env::set_var("CLICOLOR", "1");
|
||||
let expected = Some(ColorLevel {
|
||||
level: 1,
|
||||
has_basic: true,
|
||||
has_256: false,
|
||||
has_16m: false,
|
||||
});
|
||||
assert_eq!(on(Stream::Stdout), expected);
|
||||
|
||||
env::set_var("CLICOLOR", "0");
|
||||
assert_eq!(on(Stream::Stdout), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg_attr(miri, ignore)]
|
||||
fn test_clicolor_force_ansi() {
|
||||
let _test_guard = TEST_LOCK.lock().unwrap();
|
||||
set_up();
|
||||
|
||||
env::set_var("CLICOLOR", "0");
|
||||
env::set_var("CLICOLOR_FORCE", "1");
|
||||
let expected = Some(ColorLevel {
|
||||
level: 1,
|
||||
has_basic: true,
|
||||
has_256: false,
|
||||
has_16m: false,
|
||||
});
|
||||
assert_eq!(on(Stream::Stdout), expected);
|
||||
}
|
||||
}
|
12
vendor/supports-color/tests/cached.rs
vendored
Normal file
12
vendor/supports-color/tests/cached.rs
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
#[test]
|
||||
fn cached_multithreaded() {
|
||||
(0..12)
|
||||
.map(|_| {
|
||||
std::thread::spawn(|| {
|
||||
for _ in 0..1000 {
|
||||
supports_color::on_cached(supports_color::Stream::Stdout);
|
||||
}
|
||||
})
|
||||
})
|
||||
.for_each(|thread| thread.join().unwrap());
|
||||
}
|
Reference in New Issue
Block a user