1 Star 0 Fork 0

cmx490 / color

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
utils.go 1.48 KB
一键复制 编辑 原始数据 按行查看 历史
inhere 提交于 2018-08-25 00:42 . complete unit tests. some modify...
package color
import (
"io"
"os"
"strings"
)
// IsConsole 判断 w 是否为 stderr、stdout、stdin 三者之一
func IsConsole(out io.Writer) bool {
o, ok := out.(*os.File)
if !ok {
return false
}
return o == os.Stdout || o == os.Stderr || o == os.Stdin
}
// IsMSys msys(MINGW64) 环境,不一定支持颜色
func IsMSys() bool {
// like "MSYSTEM=MINGW64"
if len(os.Getenv("MSYSTEM")) > 0 {
return true
}
return false
}
// 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 {
// "TERM=xterm" support color
// "TERM=xterm-vt220" support color
// "TERM=xterm-256color" support color
// "TERM=cygwin" don't support color
if strings.Contains(os.Getenv("TERM"), "xterm") {
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
}
return false
}
// IsSupport256Color render
func IsSupport256Color() bool {
// "TERM=xterm-256color"
return strings.Contains(os.Getenv("TERM"), "256color")
}
func stringToArr(str, sep string) (arr []string) {
str = strings.TrimSpace(str)
if str == "" {
return
}
ss := strings.Split(str, sep)
for _, val := range ss {
if val = strings.TrimSpace(val); val != "" {
arr = append(arr, val)
}
}
return
}
1
https://gitee.com/cmx490/color.git
git@gitee.com:cmx490/color.git
cmx490
color
color
v1.1.6

搜索帮助

53164aa7 5694891 3bd8fe86 5694891