Documentation ¶
Overview ¶
Package color provides a wrapped standard output device like printf but with colored enhancements.
Index ¶
- func Colored(clr Color, format string, args ...any)
- func Coloredf(clr Color, format string, args ...any)
- func Dim(format string, args ...any)
- func Dimf(format string, args ...any)
- func Highlight(format string, args ...any)
- func ResetColor(c Color)
- func StripHTMLTags(s string) string
- func StripLeftTabs(s string) string
- func StripLeftTabsC(s string) string
- func StripLeftTabsOnly(s string) string
- func Text(format string, args ...any)
- func ToColor(clr Color, format string, args ...any) (str string)
- func ToColorString(clr Color) string
- func ToDim(format string, args ...any) (str string)
- func ToHighlight(format string, args ...any) (str string)
- func WrapColorAndBgTo(out io.Writer, clr, bg Color, text string)
- func WrapColorTo(out io.Writer, clr Color, text string)
- func WrapDimTo(out io.Writer, text string)
- func WrapDimToLite(out io.Writer, text string)
- func WrapHighlightTo(out io.Writer, text string)
- type Color
- type Index
- func (Index) ColoredFast(out io.Writer, clr Color, text string)
- func (Index) DimFast(out io.Writer, text string)
- func (Index) GetColorTranslater() Translator
- func (Index) GetColorTranslaterAlways() Translator
- func (Index) GetColorTranslaterNever() Translator
- func (Index) GetDummyTranslater() Translator
- func (Index) HighlightFast(out io.Writer, text string)
- func (Index) ToColorInt(s string) Color
- func (Index) ToColorString(clr Color) string
- func (Index) WrapColorAndBgTo(out io.Writer, clr, bg Color, text string)
- func (Index) WrapDimToLite(out io.Writer, text string)
- type Translator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Colored ¶
Colored outputs formatted message to stdout while logger level less than level.WarnLevel. For level.SetLevel(level.ErrorLevel), the text will be discarded.
func Coloredf ¶
Coloredf outputs formatted message to stdout while logger level less than level.WarnLevel and cmdr is in VERBOSE mode.
func Dim ¶
Dim outputs formatted message to stdout while logger level less than level.WarnLevel.
For example, after level.SetLevel(level.ErrorLevel), the text via Dim will be discarded.
func Dimf ¶
Dimf outputs formatted message to stdout while logger level less than level.WarnLevel and cmdr is in verbose mode.
For example, after level.SetLevel(level.ErrorLevel), the text via Dimf will be discarded.
While env-var VERBOSE=1, the text via Dimf will be shown.
func Highlight ¶
Highlight outputs formatted message to stdout while logger level less than level.WarnLevel. For level.SetLevel(level.ErrorLevel), the text will be discarded.
func ResetColor ¶
func ResetColor(c Color)
func StripHTMLTags ¶
StripHTMLTags aggressively strips HTML tags from a string. It will only keep anything between `>` and `<`.
func StripLeftTabs ¶
StripLeftTabs strips the least left side tab chars from lines. StripLeftTabs strips html tags too.
func StripLeftTabsC ¶
StripLeftTabsC strips the least left side tab chars from lines. StripLeftTabsC strips html tags too. At the end, StripLeftTabsC try translate color code in string.
func StripLeftTabsOnly ¶
StripLeftTabsOnly strips the least left side tab chars from lines.
func ToColorString ¶ added in v0.5.5
func ToHighlight ¶
func WrapDimToLite ¶
func WrapHighlightTo ¶
Types ¶
type Color ¶
type Color int // ANSI Escaped Sequences here
const ( // FgBlack terminal color code FgBlack Color = 30 // FgRed terminal color code FgRed Color = 31 // FgGreen terminal color code FgGreen Color = 32 // FgYellow terminal color code FgYellow Color = 33 // FgBlue terminal color code FgBlue Color = 34 // FgMagenta terminal color code FgMagenta Color = 35 // FgCyan terminal color code FgCyan Color = 36 // FgLightGray terminal color code (White) FgLightGray Color = 37 // FgDarkGray terminal color code (Gray, Light Black). // // A highlight/bright black color, maybe 50% gray. See FgLightBlack. FgDarkGray Color = 90 // FgLightBlack terminal color code (Gray, Light Black). // // A highlight/bright black color, maybe 50% gray. See FgDarkGray. FgLightBlack Color = 90 // FgLightRed terminal color code FgLightRed Color = 91 // FgLightGreen terminal color code FgLightGreen Color = 92 // FgLightYellow terminal color code FgLightYellow Color = 93 // FgLightBlue terminal color code FgLightBlue Color = 94 // FgLightMagenta terminal color code FgLightMagenta Color = 95 // FgLightCyan terminal color code FgLightCyan Color = 96 // FgWhite terminal color code (Light White) FgWhite Color = 97 // BgBlack terminal color code BgBlack Color = 40 // BgRed terminal color code BgRed Color = 41 // BgGreen terminal color code BgGreen Color = 42 // BgYellow terminal color code BgYellow Color = 43 // BgBlue terminal color code BgBlue Color = 44 // BgMagenta terminal color code BgMagenta Color = 45 // BgCyan terminal color code BgCyan Color = 46 // BgLightGray terminal color code BgLightGray Color = 47 // BgDarkGray terminal color code BgDarkGray Color = 100 // BgLightRed terminal color code BgLightRed Color = 101 // BgLightGreen terminal color code BgLightGreen Color = 102 // BgLightYellow terminal color code BgLightYellow Color = 103 // BgLightBlue terminal color code BgLightBlue Color = 104 // BgLightMagenta terminal color code BgLightMagenta Color = 105 // BgLightCyan terminal color code BgLightCyan Color = 106 // BgWhite terminal color code BgWhite Color = 107 // BgNormal terminal color code. // // All attributes become turned off. BgNormal Color = 0 // BgBoldOrBright terminal color code // // Bold or increased intensity BgBoldOrBright Color = 1 // BgDim terminal color code. // // Faint, decreased intensity, or dim. // May be implemented as a light font weight like bold. BgDim Color = 2 // BgItalic terminal color code. // // Not widely supported. Sometimes treated as inverse or blink BgItalic Color = 3 // BgUnderline terminal color code. // // Style extensions exist for Kitty, VTE, mintty, iTerm2 and Konsole. BgUnderline Color = 4 // BgBlink terminal color code. // // Slow blink, Sets blinking to less than 150 times per minute. // But in many tty it's no effect. // // Sometimes it can be used for switching to 'normal' bg state without // reset all fg and bg settings (if using bg code 0) BgBlink Color = 5 // BgRapidBlink terminal color code. // // MS-DOS ANSI.SYS, 150+ per minute; not widely supported. // // Sometimes it can be used for switching to 'normal' bg state without // reset all fg and bg settings (if using bg code 0) BgRapidBlink Color = 6 // BgInverse terminal color code. // // Swap foreground and background colors; inconsistent emulation BgInverse Color = 7 // BgHidden terminal color code. // // not widely supported. BgHidden Color = 8 // BgStrikeout terminal color code. // // marked as if for deletion. BgStrikeout Color = 9 FgDarkColor = FgLightGray FgDefault Color = 39 BgDefault Color = 49 // NoColor is not a declared ansi code but we can use it for identifying // a variable isn't initializing yet. NoColor Color = -1 )
func ToColorInt ¶ added in v0.5.5
type Index ¶ added in v0.5.20
type Index struct{}
Index is an indexer for retrieving the entries in this subpackage.
func (Index) ColoredFast ¶ added in v0.5.20
func (Index) GetColorTranslater ¶ added in v0.5.20
func (Index) GetColorTranslater() Translator
GetColorTranslater returns a translator about ANSI Escaped Code. It may or may not translating colored text depending on cabin.GetNoColorMode.
func (Index) GetColorTranslaterAlways ¶ added in v0.5.20
func (Index) GetColorTranslaterAlways() Translator
func (Index) GetColorTranslaterNever ¶ added in v0.5.20
func (Index) GetColorTranslaterNever() Translator
func (Index) GetDummyTranslater ¶ added in v0.5.20
func (Index) GetDummyTranslater() Translator
func (Index) HighlightFast ¶ added in v0.5.20
func (Index) ToColorInt ¶ added in v0.5.20
func (Index) ToColorString ¶ added in v0.5.20
func (Index) WrapColorAndBgTo ¶ added in v0.5.20
type Translator ¶
type Translator interface { Translate(s string, initialFg Color) string ColoredFast(out io.Writer, clr Color, text string) DimFast(out io.Writer, text string) HighlightFast(out io.Writer, text string) WriteColor(out io.Writer, clr Color) // echo ansi color bytes for foreground color WriteBgColor(out io.Writer, clr Color) // echo ansi color bytes for background color Reset(out io.Writer) // echo ansi color bytes for resetting color }
Translator _
func GetCPT ¶
func GetCPT() Translator
GetCPT returns a translator about ANSI Escaped Code. It may or may not translating colored text depending on cabin.GetNoColorMode.
func GetCPTC ¶
func GetCPTC() Translator
func GetCPTNC ¶
func GetCPTNC() Translator
func GetDummyTranslator ¶
func GetDummyTranslator() Translator