Skip to content

Commit

Permalink
feat(truecolor): improve check for truecolor (#14)
Browse files Browse the repository at this point in the history
* Support COLORTERM=24bit.
* As documented at https://github.com/termstandard/colors#checking-for-colorterm, COLORTERM is
  not sent over the wire with ssh by default. This means that programs that use
  supports-color don't get truecolor over ssh. To address that, check that TERM
  ends with either "direct" or "truecolor".

I think the latter check should be "-direct" or "-truecolor", but
`check_256_color` below doesn't check for a hyphen either. Should that be addressed as well?
  • Loading branch information
sunshowers committed Sep 15, 2023
1 parent ff0a31a commit 736c044
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ fn supports_color(stream: Stream) -> usize {
|| !(is_a_tty(stream) || env::var("IGNORE_IS_TERMINAL").map_or(false, |v| v != "0"))
{
0
} else if as_str(&env::var("COLORTERM")) == Ok("truecolor")
} 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
Expand Down Expand Up @@ -129,6 +130,14 @@ fn check_ansi_color(term: &str) -> bool {
|| 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")
}
Expand Down

0 comments on commit 736c044

Please sign in to comment.