Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: detect windows terminal #141

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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") != "" {
Delta456 marked this conversation as resolved.
Show resolved Hide resolved
return TrueColor
}
}
return ANSI256
}
if strings.Contains(term, "color") {
Expand Down