colors

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Reset     = command("reset")
	Bold      = command("bold")
	Underline = command("underline")
)
View Source
var (
	Red           = command("fg 1")
	Green         = command("fg 2")
	Yellow        = command("fg 3")
	Blue          = command("fg 4")
	Magenta       = command("fg 5")
	Cyan          = command("fg 6")
	BrightRed     = command("fg 9")
	BrightGreen   = command("fg 10")
	BrightBlue    = command("fg 12")
	BrightMagenta = command("fg 13")
	BrightCyan    = command("fg 14")

	RedBackground    = command("bg 1")
	GreenBackground  = command("bg 2")
	YellowBackground = command("bg 3")
	BlueBackground   = command("bg 4")

	Black = command("fg 0") // Only use with background colors.

)

Basic colors.

View Source
var (
	SpecImportant = Yellow // for particularly noteworthy messages.

	// for notes that can be skimmed or aren't very important.  Just use the standard terminal text
	// color.
	SpecUnimportant = Reset

	SpecDebug   = SpecUnimportant // for debugging.
	SpecInfo    = Magenta         // for information.
	SpecError   = Red             // for errors.
	SpecWarning = Yellow          // for warnings.

	SpecHeadline    = BrightMagenta + Bold // for headings in the CLI.
	SpecSubHeadline = Bold                 // for subheadings in the CLI.
	SpecPrompt      = Cyan + Bold          // for prompting the user.
	SpecAttention   = BrightRed            // for messages that are meant to grab attention.

	// for simple notes.  Just use the standard terminal text color.
	SpecNote = Reset

	SpecCreate            = Green         // for adds (in the diff sense).
	SpecUpdate            = Yellow        // for changes (in the diff sense).
	SpecReplace           = BrightMagenta // for replacements (in the diff sense).
	SpecDelete            = Red           // for deletes (in the diff sense).
	SpecCreateReplacement = BrightGreen   // for replacement creates (in the diff sense).
	SpecDeleteReplaced    = BrightRed     // for replacement deletes (in the diff sense).
	SpecRead              = BrightCyan    // for reads
)

Special predefined colors for logical conditions.

Functions

func Colorize

func Colorize(s fmt.Stringer) string

func Highlight added in v0.14.0

func Highlight(s, text, commands string) string

Highlight takes an input string, a sequence of commands, and replaces all occurrences of that string with a "highlighted" version surrounded by those commands and a final reset afterwards.

func TrimColorizedString

func TrimColorizedString(v string, maxRuneLength int) string

TrimColorizedString takes a string with embedded color tags and returns a new string (still with embedded color tags) such that the length of the *non-tag* portion of the string is no greater than maxLength. This is useful for scenarios where the string has to be printed in a a context where there is a max allowed width. In these scenarios, we can't just measure the length of the string as the embedded color tags would count against it, even though they end up with no length when actually interpretted by the console.

func TrimPartialCommand added in v0.16.4

func TrimPartialCommand(s string) string

TrimPartialCommand returns the input string with any partial colorization command trimmed off of the right end of the string.

Types

type Colorization

type Colorization string
const (
	// Auto determines if we should colorize depending on the surrounding environment we're in.
	Auto Colorization = "auto"
	// Always colorizes text.
	Always Colorization = "always"
	// Never colorizes text.
	Never Colorization = "never"
	// Raw returns text with the raw control sequences, rather than colorizing them.
	Raw Colorization = "raw"
)

func (Colorization) Colorize

func (c Colorization) Colorize(v string) string

Colorize conditionally colorizes the given string based on the kind of colorization selected.

Jump to

Keyboard shortcuts

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