Skip to content

Commit

Permalink
make sure detectTerminalColor() doesn't panic on macOS (#19)
Browse files Browse the repository at this point in the history
Co-authored-by: Sharif Elgamal <[email protected]>
  • Loading branch information
Delta456 and sharifelgamal authored Aug 23, 2021
1 parent bed6c09 commit 14a0c9e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions detect_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package box

import (
"errors"
"fmt"
"io/ioutil"
"log"
Expand All @@ -27,15 +28,17 @@ func errorMsg(msg string) {
func detectTerminalColor() terminfo.ColorLevel {
// Detect WSL as it has True Color support
wsl, err := ioutil.ReadFile("/proc/sys/kernel/osrelease")
if err != nil {
if err != nil && !errors.Is(err, os.ErrNotExist) {
log.Fatal(err)
}
// 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))
if strings.Contains(wslLower, "microsoft") {
return terminfo.ColorLevelMillions
if string(wsl) != "" {
wslLower := strings.ToLower(string(wsl))
if strings.Contains(wslLower, "microsoft") {
return terminfo.ColorLevelMillions
}
}
level, err := terminfo.ColorLevelFromEnv()
if err != nil {
Expand Down

0 comments on commit 14a0c9e

Please sign in to comment.