Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions termenv_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
package termenv

import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -57,6 +60,22 @@ func (o *Output) ColorProfile() Profile {
}

if strings.Contains(term, "256color") {
// Check for WSL
wsl, err := ioutil.ReadFile("/proc/sys/kernel/osrelease")
// Additional check for Mac OS as it doesn't have "/proc/" folder
if err != nil && !errors.Is(err, os.ErrNotExist) {
return ANSI256
}
if string(wsl) != "" {
// Lowercasing every content inside "/proc/sys/kernal/osrelease"
// because it gives "Microsoft" for WSL and "microsoft" for WSL 2
// so no need of checking twice
wslLower := strings.ToLower(string(wsl))
// Also check if the terminal used is Windows Terminal
if strings.Contains(wslLower, "Microsoft") && os.Getenv("WT_SESSION") != "" {
return TrueColor
}
}
return ANSI256
}
if strings.Contains(term, "color") {
Expand Down