Skip to content

Commit

Permalink
Detect true color support for dynamic terminfo
Browse files Browse the repository at this point in the history
  • Loading branch information
zyedidia committed Jan 6, 2020
1 parent e02c8a0 commit b7c85af
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions terminfo/dynamic/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package dynamic
import (
"bytes"
"errors"
"os"
"os/exec"
"regexp"
"strconv"
Expand Down Expand Up @@ -421,5 +422,33 @@ func LoadTerminfo(name string) (*terminfo.Terminfo, string, error) {
t.SetFgBg = fg + ";" + bg
}

addtruecolor := false
switch os.Getenv("COLORTERM") {
case "truecolor", "24bit", "24-bit":
addtruecolor = true
}
switch os.Getenv("TCELL_TRUECOLOR") {
case "":
case "disable":
addtruecolor = false
default:
addtruecolor = true
}

// If the user has requested 24-bit color with $COLORTERM, then
// amend the value (unless already present). This means we don't
// need to have a value present.
if addtruecolor &&
t.SetFgBgRGB == "" &&
t.SetFgRGB == "" &&
t.SetBgRGB == "" {

// Supply vanilla ISO 8613-6:1994 24-bit color sequences.
t.SetFgRGB = "\x1b[38;2;%p1%d;%p2%d;%p3%dm"
t.SetBgRGB = "\x1b[48;2;%p1%d;%p2%d;%p3%dm"
t.SetFgBgRGB = "\x1b[38;2;%p1%d;%p2%d;%p3%d;" +
"48;2;%p4%d;%p5%d;%p6%dm"
}

return t, tc.desc, nil
}

0 comments on commit b7c85af

Please sign in to comment.