Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( Reset = Command("reset") Bold = Command("bold") Underline = Command("underline") )
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") )
Basic colors.
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. 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). // for reads (relatively unimportant). Just use the standard terminal text color. SpecRead = Reset )
Special predefined colors for logical conditions.
Functions ¶
func Highlight ¶ added in v0.14.0
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 ¶
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 ¶
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
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
Colorization is an instruction to perform a certain kind of colorization.
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.