Skip to content

Commit

Permalink
Add Windows color support detection
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Feb 2, 2022
1 parent 3129ed3 commit 1085c27
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions termenv_windows.go
Expand Up @@ -4,10 +4,38 @@
package termenv

import (
"os"
"strconv"

"golang.org/x/sys/windows"
)

func colorProfile() Profile {
if os.Getenv("ConEmuANSI") == "ON" {
return TrueColor
}

winVersion, _, buildNumber := windows.RtlGetNtVersionNumbers()
if buildNumber < 10586 || winVersion < 10 {
// No ANSI support before Windows 10 build 10586.
if os.Getenv("ANSICON") != "" {
conVersion := os.Getenv("ANSICON_VER")
cv, err := strconv.ParseInt(conVersion, 10, 64)
if err != nil || cv < 181 {
// No 8 bit color support before v1.81 release.
return ANSI
}

return ANSI256
}

return Ascii
}
if buildNumber < 14931 {
// No true color support before build 14931.
return ANSI256
}

return TrueColor
}

Expand Down

0 comments on commit 1085c27

Please sign in to comment.