代码拉取完成,页面将自动刷新
package envutil
import (
"io"
"os"
"runtime"
"strings"
"gitee.com/ckbabby/goutil/sysutil"
)
// IsWin system. linux windows darwin
func IsWin() bool {
return runtime.GOOS == "windows"
}
// IsMac system
func IsMac() bool {
return runtime.GOOS == "darwin"
}
// IsLinux system
func IsLinux() bool {
return runtime.GOOS == "linux"
}
// IsConsole check out is console env. alias of the sysutil.IsConsole()
func IsConsole(out io.Writer) bool {
return sysutil.IsConsole(out)
}
// IsMSys msys(MINGW64) env. alias of the sysutil.IsMSys()
func IsMSys() bool {
return sysutil.IsMSys()
}
// HasShellEnv has shell env check.
// Usage:
// HasShellEnv("sh")
// HasShellEnv("bash")
func HasShellEnv(shell string) bool {
return sysutil.HasShellEnv(shell)
}
// Support color:
// "TERM=xterm"
// "TERM=xterm-vt220"
// "TERM=xterm-256color"
// "TERM=screen-256color"
// "TERM=tmux-256color"
// "TERM=rxvt-unicode-256color"
// Don't support color:
// "TERM=cygwin"
var specialColorTerms = map[string]bool{
"alacritty": true,
"screen-256color": true,
"tmux-256color": true,
"rxvt-unicode-256color": true,
}
// IsSupportColor check current console is support color.
//
// Supported:
// linux, mac, or windows's ConEmu, Cmder, putty, git-bash.exe
// Not support:
// windows cmd.exe, powerShell.exe
func IsSupportColor() bool {
envTerm := os.Getenv("TERM")
if strings.Contains(envTerm, "xterm") {
return true
}
// it's special color term
if _, ok := specialColorTerms[envTerm]; ok {
return true
}
// like on ConEmu software, e.g "ConEmuANSI=ON"
if os.Getenv("ConEmuANSI") == "ON" {
return true
}
// like on ConEmu software, e.g "ANSICON=189x2000 (189x43)"
if os.Getenv("ANSICON") != "" {
return true
}
// up: if support 256-color, can also support basic color.
return IsSupport256Color()
}
// IsSupport256Color render
func IsSupport256Color() bool {
// "TERM=xterm-256color"
// "TERM=screen-256color"
// "TERM=tmux-256color"
// "TERM=rxvt-unicode-256color"
supported := strings.Contains(os.Getenv("TERM"), "256color")
if !supported {
// up: if support true-color, can also support 256-color.
supported = IsSupportTrueColor()
}
return supported
}
// IsSupportTrueColor render. IsSupportRGBColor
func IsSupportTrueColor() bool {
// "COLORTERM=truecolor"
return strings.Contains(os.Getenv("COLORTERM"), "truecolor")
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。