package termenv
Import Path
github.com/gookit/goutil/x/termenv (on go.dev)
Dependency Relation
imports 11 packages, and imported by one package
Involved Source Files
detect_color.go
detect_nonwin.go
Package termenv provides detect color support of the current terminal.
And with some utils for terminal env.
util.go
Package-Level Type Names (only one)
ColorLevel is the color level supported by a terminal.
String returns the string name of the color level.
ColorLevel : expvar.Var
ColorLevel : fmt.Stringer
func DetectColorLevel() ColorLevel
func TermColorLevel() ColorLevel
func github.com/gookit/goutil/x/ccolor.Level() ColorLevel
func SetColorLevel(level ColorLevel)
const TermColor16
const TermColor256
const TermColorNone
const TermColorTrue
Package-Level Functions (total 18)
CurrentShell get current used shell env file.
eg "/bin/zsh" "/bin/bash".
if onlyName=true, will return "zsh", "bash"
DetectColorLevel for current env
NOTICE: The method will detect terminal info each time.
if only want to get current color level, please direct call IsSupportColor() or TermColorLevel()
DisableColor in the current terminal
ForceEnableColor flags value. TIP: use for unit testing.
Usage:
ccolor.ForceEnableColor()
defer ccolor.RevertColorSupport()
GetTermSize for current console terminal. will first try to get from environment variables COLUMNS and LINES.
HasShellEnv has shell env check.
Usage:
HasShellEnv("sh")
HasShellEnv("bash")
IsShellSpecialVar reports whether the character identifies a special
shell variable such as $*.
IsSupport256Color returns true if the terminal supports 256 colors.
IsSupportColor returns true if the terminal supports color.
IsSupportTrueColor returns true if the terminal supports true color.
IsTerminal 检查是否为终端设备中
LastErr returns the last error.
NoColor returns true if the NO_COLOR environment variable is set.
ReadPassword from console terminal
RevertColorSupport flags to init value.
SetColorLevel value force.
SetDebugMode sets debug mode.
TermColorLevel returns the color support level for the current terminal.
Package-Level Constants (total 4)
const TermColor16 ColorLevel = 1 // 16(4bit) ANSI color supported const TermColor256 ColorLevel = 2 // 256(8bit) color supported const TermColorNone ColorLevel = 0 // not support color const TermColorTrue ColorLevel = 3 // support TRUE(RGB) color
![]() |
The pages are generated with Golds v0.8.4. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |