aboutsummaryrefslogtreecommitdiff
path: root/vendor/supports-unicode/src
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/supports-unicode/src
parent5ecd8cf2cba827454317368b68571df0d13d7842 (diff)
downloadfparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz
fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/supports-unicode/src')
-rw-r--r--vendor/supports-unicode/src/lib.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/vendor/supports-unicode/src/lib.rs b/vendor/supports-unicode/src/lib.rs
new file mode 100644
index 0000000..b47b39b
--- /dev/null
+++ b/vendor/supports-unicode/src/lib.rs
@@ -0,0 +1,42 @@
+#![doc = include_str!("../README.md")]
+
+/// possible stream sources
+#[derive(Clone, Copy, Debug)]
+pub enum Stream {
+ Stdout,
+ Stderr,
+}
+
+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(),
+ }
+}
+
+pub fn on(stream: Stream) -> bool {
+ if !is_a_tty(stream) {
+ // If we're just piping out, it's fine to spit out unicode! :)
+ true
+ } else if std::env::consts::OS == "windows" {
+ // Just a handful of things!
+ std::env::var("CI").is_ok()
+ || std::env::var("WT_SESSION").is_ok() // Windows Terminal
+ || std::env::var("ConEmuTask") == Ok("{cmd:Cmder}".into()) // ConEmu and cmder
+ || std::env::var("TERM_PROGRAM") == Ok("vscode".into())
+ || std::env::var("TERM") == Ok("xterm-256color".into())
+ || std::env::var("TERM") == Ok("alacritty".into())
+ } else if std::env::var("TERM") == Ok("linux".into()) {
+ // Linux kernel console. Maybe redundant with the below?...
+ false
+ } else {
+ // From https://github.com/iarna/has-unicode/blob/master/index.js
+ let ctype = std::env::var("LC_ALL")
+ .or_else(|_| std::env::var("LC_CTYPE"))
+ .or_else(|_| std::env::var("LANG"))
+ .unwrap_or_else(|_| "".into())
+ .to_uppercase();
+ ctype.ends_with("UTF8") || ctype.ends_with("UTF-8")
+ }
+}