gocolor

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2022 License: Apache-2.0 Imports: 0 Imported by: 0

README

gocolor

A tiny cross-platform cross-platform terminal color library that supports enabling and disabling colors.

Uses colors from https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences?redirectedfrom=MSDN#text-formatting

Tested on MacOS and (occasionally) on Ubuntu 20 and Windows 10.

Usage

See tests. Also see mattn/go-isatty to test if your program is working with a tty before you enable color.

TestWithReflection.png

Inspirations

Documentation

Overview

Code generated by scripts/color_gen.py. DO NOT EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnableConsole

func EnableConsole() error

EnableConsole enables color printing on Windows and is a no-op on non-Windows platforms (they enable color printing by default).

Types

type Code added in v0.0.2

type Code string

Code is a color code string

type Color

type Color struct {

	// BgBlack - Applies non-bold/bright black to background
	BgBlack Code

	// BgBlackBright - Applies bold/bright black to background
	BgBlackBright Code

	// BgBlue - Applies non-bold/bright blue to background
	BgBlue Code

	// BgBlueBright - Applies bold/bright blue to background
	BgBlueBright Code

	// BgCyan - Applies non-bold/bright cyan to background
	BgCyan Code

	// BgCyanBright - Applies bold/bright cyan to background
	BgCyanBright Code

	// BgDefault - Applies only the background portion of the defaults (see 0)
	BgDefault Code

	// BgExtended - Applies extended color value to the background (see details below)
	BgExtended Code

	// BgGreen - Applies non-bold/bright green to background
	BgGreen Code

	// BgGreenBright - Applies bold/bright green to background
	BgGreenBright Code

	// BgMagenta - Applies non-bold/bright magenta to background
	BgMagenta Code

	// BgMagentaBright - Applies bold/bright magenta to background
	BgMagentaBright Code

	// BgRed - Applies non-bold/bright red to background
	BgRed Code

	// BgRedBright - Applies bold/bright red to background
	BgRedBright Code

	// BgWhite - Applies non-bold/bright white to background
	BgWhite Code

	// BgWhiteBright - Applies bold/bright white to background
	BgWhiteBright Code

	// BgYellow - Applies non-bold/bright yellow to background
	BgYellow Code

	// BgYellowBright - Applies bold/bright yellow to background
	BgYellowBright Code

	// Bold - Applies brightness/intensity flag to foreground color
	Bold Code

	// Default - Returns all attributes to the default state prior to modification
	Default Code

	// FgBlack - Applies non-bold/bright black to foreground
	FgBlack Code

	// FgBlackBright - Applies bold/bright black to foreground
	FgBlackBright Code

	// FgBlue - Applies non-bold/bright blue to foreground
	FgBlue Code

	// FgBlueBright - Applies bold/bright blue to foreground
	FgBlueBright Code

	// FgCyan - Applies non-bold/bright cyan to foreground
	FgCyan Code

	// FgCyanBright - Applies bold/bright cyan to foreground
	FgCyanBright Code

	// FgDefault - Applies only the foreground portion of the defaults (see 0)
	FgDefault Code

	// FgExtended - Applies extended color value to the foreground (see details below)
	FgExtended Code

	// FgGreen - Applies non-bold/bright green to foreground
	FgGreen Code

	// FgGreenBright - Applies bold/bright green to foreground
	FgGreenBright Code

	// FgMagenta - Applies non-bold/bright magenta to foreground
	FgMagenta Code

	// FgMagentaBright - Applies bold/bright magenta to foreground
	FgMagentaBright Code

	// FgRed - Applies non-bold/bright red to foreground
	FgRed Code

	// FgRedBright - Applies bold/bright red to foreground
	FgRedBright Code

	// FgWhite - Applies non-bold/bright white to foreground
	FgWhite Code

	// FgWhiteBright - Applies bold/bright white to foreground
	FgWhiteBright Code

	// FgYellow - Applies non-bold/bright yellow to foreground
	FgYellow Code

	// FgYellowBright - Applies bold/bright yellow to foreground
	FgYellowBright Code

	// Negative - Swaps foreground and background colors
	Negative Code

	// Nobold - Removes brightness/intensity flag from foreground color
	Nobold Code

	// Nounderline - Removes underline
	Nounderline Code

	// Positive - Returns foreground/background to normal
	Positive Code

	// Underline - Adds underline
	Underline Code
}

Color contains all colors listed in https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences?redirectedfrom=MSDN#text-formatting

func Prepare

func Prepare(startEnabled bool) (Color, error)

Prepare is a convenience method that calls EnableConsole and returns an enabled color if there's no error and startEnabled is True, and a disabled color and the error otherwise.

func (*Color) Add

func (c *Color) Add(color Code, message string) string

Add colors a message and resets the console color afterwards

func (*Color) DisableAll added in v0.0.2

func (c *Color) DisableAll()

DisableAll sets all colors to the empty string, effectively disabling color output

func (*Color) EnableAll added in v0.0.2

func (c *Color) EnableAll()

EnableAll sets all colors to their color codes

func (*Color) Func added in v0.0.2

func (c *Color) Func(codePtr *Code) ColorFunc

Func generates a ColorFunc from a color code. It uses the address of the code instead of the value because the code's value might change (for example to "" when Disable() is called)

type ColorFunc added in v0.0.2

type ColorFunc = func(message string) string

ColorFunc colors a message and resets the console color afterwards. Use Func() to generate a ColorFunc with a specific color

Jump to

Keyboard shortcuts

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