Documentation
¶
Overview ¶
Package termenv provides detect color support of the current terminal. And with some utils for terminal env.
Index ¶
- func CurrentShell(onlyName bool, fallbackShell ...string) string
- func DisableColor()
- func ForceEnableColor()
- func GetTermSize(refresh ...bool) (w int, h int)
- func HasShellEnv(shell string) bool
- func IsShellSpecialVar(c uint8) bool
- func IsSupport256Color() bool
- func IsSupportColor() bool
- func IsSupportTrueColor() bool
- func IsTerminal() bool
- func LastErr() error
- func NoColor() bool
- func ReadPassword(question ...string) string
- func RevertColorSupport()
- func SetColorLevel(level ColorLevel)
- func SetDebugMode(enable bool)
- type ColorLevel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CurrentShell ¶
CurrentShell get current used shell env file.
eg "/bin/zsh" "/bin/bash". if onlyName=true, will return "zsh", "bash"
func ForceEnableColor ¶
func ForceEnableColor()
ForceEnableColor flags value. TIP: use for unit testing.
Usage:
ccolor.ForceEnableColor() defer ccolor.RevertColorSupport()
func GetTermSize ¶
GetTermSize for current console terminal. will first try to get from environment variables COLUMNS and LINES.
func IsShellSpecialVar ¶
IsShellSpecialVar reports whether the character identifies a special shell variable such as $*.
func IsSupport256Color ¶
func IsSupport256Color() bool
IsSupport256Color returns true if the terminal supports 256 colors.
func IsSupportColor ¶
func IsSupportColor() bool
IsSupportColor returns true if the terminal supports color.
func IsSupportTrueColor ¶
func IsSupportTrueColor() bool
IsSupportTrueColor returns true if the terminal supports true color.
Types ¶
type ColorLevel ¶
type ColorLevel uint8
ColorLevel is the color level supported by a terminal.
const ( TermColorNone ColorLevel = iota // not support color TermColor16 // 16(4bit) ANSI color supported TermColor256 // 256(8bit) color supported TermColorTrue // support TRUE(RGB) color )
func DetectColorLevel ¶
func DetectColorLevel() ColorLevel
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()
func TermColorLevel ¶
func TermColorLevel() ColorLevel
TermColorLevel returns the color support level for the current terminal.
func (ColorLevel) String ¶
func (l ColorLevel) String() string
String returns the string name of the color level.