termenv

package
v0.7.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2026 License: MIT Imports: 11 Imported by: 2

Documentation

Overview

Package termenv provides detect color support of the current terminal. And with some utils for terminal env.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentShell

func CurrentShell(onlyName bool, fallbackShell ...string) string

CurrentShell get current used shell env file.

eg "/bin/zsh" "/bin/bash". if onlyName=true, will return "zsh", "bash"

func DisableColor

func DisableColor()

DisableColor in the current terminal

func ForceEnableColor

func ForceEnableColor()

ForceEnableColor flags value. TIP: use for unit testing.

Usage:

ccolor.ForceEnableColor()
defer ccolor.RevertColorSupport()

func GetTermSize

func GetTermSize(refresh ...bool) (w int, h int)

GetTermSize for current console terminal. will first try to get from environment variables COLUMNS and LINES.

func HasShellEnv

func HasShellEnv(shell string) bool

HasShellEnv has shell env check.

Usage:

HasShellEnv("sh")
HasShellEnv("bash")

func IsShellSpecialVar

func IsShellSpecialVar(c uint8) bool

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.

func IsTerminal

func IsTerminal() bool

IsTerminal 检查是否为终端设备中

func LastErr

func LastErr() error

LastErr returns the last error.

func NoColor

func NoColor() bool

NoColor returns true if the NO_COLOR environment variable is set.

func ReadPassword

func ReadPassword(question ...string) string

ReadPassword from console terminal

func RevertColorSupport

func RevertColorSupport()

RevertColorSupport flags to init value.

func SetColorLevel

func SetColorLevel(level ColorLevel)

SetColorLevel value force.

func SetDebugMode

func SetDebugMode(enable bool)

SetDebugMode sets debug mode.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL