1#![doc = include_str!("../README.md")]
2
3#[derive(Clone, Copy, Debug)]
5pub enum Stream {
6 Stdout,
7 Stderr,
8}
9
10fn is_a_tty(stream: Stream) -> bool {
11 use std::io::IsTerminal;
12 match stream {
13 Stream::Stdout => std::io::stdout().is_terminal(),
14 Stream::Stderr => std::io::stderr().is_terminal(),
15 }
16}
17
18pub fn on(stream: Stream) -> bool {
21 if !is_a_tty(stream) {
22 true
24 } else {
25 supports_unicode()
26 }
27}
28
29pub fn supports_unicode() -> bool {
32 if std::env::consts::OS == "windows" {
33 std::env::var("CI").is_ok()
35 || std::env::var("WT_SESSION").is_ok() || std::env::var("ConEmuTask") == Ok("{cmd:Cmder}".into()) || std::env::var("TERM_PROGRAM") == Ok("vscode".into())
38 || std::env::var("TERM") == Ok("xterm-256color".into())
39 || std::env::var("TERM") == Ok("alacritty".into())
40 } else if std::env::var("TERM") == Ok("linux".into()) {
41 false
43 } else {
44 let ctype = std::env::var("LC_ALL")
46 .or_else(|_| std::env::var("LC_CTYPE"))
47 .or_else(|_| std::env::var("LANG"))
48 .unwrap_or_else(|_| "".into())
49 .to_uppercase();
50 ctype.ends_with("UTF8") || ctype.ends_with("UTF-8")
51 }
52}