File: detect_nonwin.go

package info (click to toggle)
golang-github-gookit-color 1.5.4-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,708 kB
  • sloc: sh: 101; makefile: 7
file content (49 lines) | stat: -rw-r--r-- 1,159 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//go:build !windows
// +build !windows

// The method in the file has no effect
// Only for compatibility with non-Windows systems

package color

import (
	"strings"
	"syscall"

	"github.com/xo/terminfo"
)

// detect special term color support
func detectSpecialTermColor(termVal string) (Level, bool) {
	if termVal == "" {
		return terminfo.ColorLevelNone, false
	}

	debugf("terminfo check fail - fallback detect color by check TERM value")

	// on TERM=screen:
	// - support 256, not support true-color. test on macOS
	if termVal == "screen" {
		return terminfo.ColorLevelHundreds, false
	}

	if strings.Contains(termVal, "256color") {
		return terminfo.ColorLevelHundreds, false
	}

	if strings.Contains(termVal, "xterm") {
		return terminfo.ColorLevelHundreds, false
		// return terminfo.ColorLevelBasic, false
	}

	// return terminfo.ColorLevelNone, nil
	return terminfo.ColorLevelBasic, false
}

// IsTerminal returns true if the given file descriptor is a terminal.
//
// Usage:
// 	IsTerminal(os.Stdout.Fd())
func IsTerminal(fd uintptr) bool {
	return fd == uintptr(syscall.Stdout) || fd == uintptr(syscall.Stdin) || fd == uintptr(syscall.Stderr)
}