colors

package
v0.15.4 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Black         = Command("fg 0")
	Red           = Command("fg 1")
	Green         = Command("fg 2")
	Yellow        = Command("fg 3")
	Blue          = Command("fg 4")
	Magenta       = Command("fg 5")
	Cyan          = Command("fg 6")
	White         = Command("fg 7")
	BrightBlack   = Command("fg 8")
	BrightRed     = Command("fg 9")
	BrightGreen   = Command("fg 10")
	BrightYellow  = Command("fg 11")
	BrightBlue    = Command("fg 12")
	BrightMagenta = Command("fg 13")
	BrightCyan    = Command("fg 14")
	BrightWhite   = Command("fg 15")
)

Basic colors.

View Source
var (
	Bold      = Command("bold")
	Underline = Command("underline")
)
View Source
var (
	SpecImportant   = BrightYellow // for particularly noteworthy messages.
	SpecUnimportant = BrightBlack  // for notes that can be skimmed or aren't very important.

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

	SpecLocation  = Cyan      // for source locations.
	SpecAttention = BrightRed // for messages that are meant to grab attention.
	SpecNote      = White     // for simple notes.

	SpecCreate            = Green        // for adds (in the diff sense).
	SpecUpdate            = BrightYellow // for changes (in the diff sense).
	SpecRead              = BrightWhite  // for reads (relatively unimportant).
	SpecReplace           = Yellow       // 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).
)

Special predefined colors for logical conditions.

View Source
var Reset = Command("reset")

Functions

func Colorize

func Colorize(s fmt.Stringer) string

func Command

func Command(s string) 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 SplitIntoTextAndTags

func SplitIntoTextAndTags(v string) []string

SplitIntoTextAndTags breaks up a colorized string into alternating sections of a raw-text-chunk and then a color-tag. The returned array will always be non empty, with the first and last elements in the array being (possibly empty) raw-text-chunks. For example, if you started with "<%fg 8>hello<%fg 7>", this would return: ["", "<%fg 8>", "hello", "<%fg 7>", ""]

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.

Types

type Colorization

type Colorization string

Colorization is an instruction to perform a certain kind of colorization.

const (
	// 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