(preference: &str)
| 68 | } |
| 69 | |
| 70 | pub fn resolve_effective_color_scheme(preference: &str) -> EffectiveColorScheme { |
| 71 | if std::env::var_os("NO_COLOR").is_some() { |
| 72 | return EffectiveColorScheme::Monochrome; |
| 73 | } |
| 74 | if matches!(std::env::var("CLICOLOR").ok().as_deref(), Some("0")) { |
| 75 | return EffectiveColorScheme::Monochrome; |
| 76 | } |
| 77 | |
| 78 | match preference.trim().to_ascii_lowercase().as_str() { |
| 79 | "mono" | "monochrome" | "nocolor" | "no_color" => EffectiveColorScheme::Monochrome, |
| 80 | "ansi" | "ansi16" => EffectiveColorScheme::Ansi16, |
| 81 | "truecolor" | "24bit" => EffectiveColorScheme::Truecolor, |
| 82 | "" | "default" | "auto" | _ => { |
| 83 | if terminal_supports_truecolor() { |
| 84 | EffectiveColorScheme::Truecolor |
| 85 | } else { |
| 86 | EffectiveColorScheme::Ansi16 |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | fn terminal_supports_truecolor() -> bool { |
| 93 | if !std::io::stdout().is_terminal() { |
no test coverage detected