Codebase list golang-github-daviddengcn-go-colortext / upstream/0.0_git20150719.0.3b18c85 ct.go
upstream/0.0_git20150719.0.3b18c85

Tree @upstream/0.0_git20150719.0.3b18c85 (Download .tar.gz)

ct.go @upstream/0.0_git20150719.0.3b18c85raw · history · blame

/*
ct package provides functions to change the color of console text.

Under windows platform, the Console api is used. Under other systems, ANSI text mode is used.
*/
package ct

// Color is the type of color to be set.
type Color int

const (
	// No change of color
	None = Color(iota)
	Black
	Red
	Green
	Yellow
	Blue
	Magenta
	Cyan
	White
)

/*
ResetColor resets the foreground and background to original colors
*/
func ResetColor() {
	resetColor()
}

// ChangeColor sets the foreground and background colors. If the value of the color is None,
// the corresponding color keeps unchanged.
// If fgBright or bgBright is set true, corresponding color use bright color. bgBright may be
// ignored in some OS environment.
func ChangeColor(fg Color, fgBright bool, bg Color, bgBright bool) {
	changeColor(fg, fgBright, bg, bgBright)
}

// Foreground changes the foreground color.
func Foreground(cl Color, bright bool) {
	ChangeColor(cl, bright, None, false)
}

// Background changes the background color.
func Background(cl Color, bright bool) {
	ChangeColor(None, false, cl, bright)
}