Documentation ¶
Overview ¶
Package gchalk is terminal string styling for go done right, with full Linux, MacOS, and painless Windows 10 support.
GChalk is a library heavily inspired by https://github.com/chalk/chalk, the popular Node.js terminal color library, and using golang ports of supports-color (https://github.com/jwalton/go-supportscolor) and ansi-styles (https://github.com/jwalton/gchalk/pkg/ansistyles).
A very simple usage example would be:
fmt.Println(gchalk.Blue("This line is blue"))
Note that this works on all platforms - there's no need to write to a special stream or use a special print function to get color on Windows 10.
Some examples:
// Combine styled and normal strings fmt.Println(gchalk.Blue("Hello") + " World" + gchalk.Red("!")) // Compose multiple styles using the chainable API fmt.Println(gchalk.WithBlue().WithBgRed().Bold("Hello world!")) // Pass in multiple arguments fmt.Println(gchalk.Blue("Hello", "World!", "Foo", "bar", "biz", "baz")) // Nest styles fmt.Println(gchalk.Green( "I am a green line " + gchalk.WithBlue().WithUnderline().Bold("with a blue substring") + " that becomes green again!" )) // Use RGB colors in terminal emulators that support it. fmt.Println(gchalk.WithRGB(123, 45, 67).Underline("Underlined reddish color")) fmt.Println(gchalk.WithHex("#DEADED").Bold("Bold gray!")) // Write to stderr: os.Stderr.WriteString(gchalk.Stderr.Red("Ohs noes!\n"))
See the README.md for more details.
Index ¶
- Variables
- func BgBlack(str ...string) string
- func BgBlue(str ...string) string
- func BgBrightBlack(str ...string) string
- func BgBrightBlue(str ...string) string
- func BgBrightCyan(str ...string) string
- func BgBrightGreen(str ...string) string
- func BgBrightMagenta(str ...string) string
- func BgBrightRed(str ...string) string
- func BgBrightWhite(str ...string) string
- func BgBrightYellow(str ...string) string
- func BgCyan(str ...string) string
- func BgGray(str ...string) string
- func BgGreen(str ...string) string
- func BgGrey(str ...string) string
- func BgMagenta(str ...string) string
- func BgRed(str ...string) string
- func BgWhite(str ...string) string
- func BgYellow(str ...string) string
- func Black(str ...string) string
- func Blue(str ...string) string
- func Bold(str ...string) string
- func BrightBlack(str ...string) string
- func BrightBlue(str ...string) string
- func BrightCyan(str ...string) string
- func BrightGreen(str ...string) string
- func BrightMagenta(str ...string) string
- func BrightRed(str ...string) string
- func BrightWhite(str ...string) string
- func BrightYellow(str ...string) string
- func Cyan(str ...string) string
- func Dim(str ...string) string
- func Gray(str ...string) string
- func Green(str ...string) string
- func Grey(str ...string) string
- func Hidden(str ...string) string
- func Inverse(str ...string) string
- func Italic(str ...string) string
- func Magenta(str ...string) string
- func Overline(str ...string) string
- func Red(str ...string) string
- func Reset(str ...string) string
- func SetLevel(level ColorLevel)
- func Strikethrough(str ...string) string
- func Underline(str ...string) string
- func White(str ...string) string
- func Yellow(str ...string) string
- type Builder
- func New(options ...Option) *Builder
- func WithAnsi(code uint8) *Builder
- func WithAnsi256(code uint8) *Builder
- func WithBgAnsi(code uint8) *Builder
- func WithBgAnsi256(code uint8) *Builder
- func WithBgBlack() *Builder
- func WithBgBlue() *Builder
- func WithBgBrightBlack() *Builder
- func WithBgBrightBlue() *Builder
- func WithBgBrightCyan() *Builder
- func WithBgBrightGreen() *Builder
- func WithBgBrightMagenta() *Builder
- func WithBgBrightRed() *Builder
- func WithBgBrightWhite() *Builder
- func WithBgBrightYellow() *Builder
- func WithBgCyan() *Builder
- func WithBgGray() *Builder
- func WithBgGreen() *Builder
- func WithBgGrey() *Builder
- func WithBgHex(hex string) *Builder
- func WithBgMagenta() *Builder
- func WithBgRGB(r uint8, g uint8, b uint8) *Builder
- func WithBgRed() *Builder
- func WithBgWhite() *Builder
- func WithBgYellow() *Builder
- func WithBlack() *Builder
- func WithBlue() *Builder
- func WithBold() *Builder
- func WithBrightBlack() *Builder
- func WithBrightBlue() *Builder
- func WithBrightCyan() *Builder
- func WithBrightGreen() *Builder
- func WithBrightMagenta() *Builder
- func WithBrightRed() *Builder
- func WithBrightWhite() *Builder
- func WithBrightYellow() *Builder
- func WithCyan() *Builder
- func WithDim() *Builder
- func WithGray() *Builder
- func WithGreen() *Builder
- func WithGrey() *Builder
- func WithHex(hex string) *Builder
- func WithHidden() *Builder
- func WithInverse() *Builder
- func WithItalic() *Builder
- func WithMagenta() *Builder
- func WithOverline() *Builder
- func WithRGB(r uint8, g uint8, b uint8) *Builder
- func WithRed() *Builder
- func WithReset() *Builder
- func WithStrikethrough() *Builder
- func WithStyle(styles ...string) (*Builder, error)
- func WithStyleMust(styles ...string) *Builder
- func WithUnderline() *Builder
- func WithWhite() *Builder
- func WithYellow() *Builder
- func (builder *Builder) Ansi(code uint8) ColorFn
- func (builder *Builder) Ansi256(code uint8) ColorFn
- func (builder *Builder) BgAnsi(code uint8) ColorFn
- func (builder *Builder) BgAnsi256(code uint8) ColorFn
- func (builder *Builder) BgBlack(str ...string) string
- func (builder *Builder) BgBlue(str ...string) string
- func (builder *Builder) BgBrightBlack(str ...string) string
- func (builder *Builder) BgBrightBlue(str ...string) string
- func (builder *Builder) BgBrightCyan(str ...string) string
- func (builder *Builder) BgBrightGreen(str ...string) string
- func (builder *Builder) BgBrightMagenta(str ...string) string
- func (builder *Builder) BgBrightRed(str ...string) string
- func (builder *Builder) BgBrightWhite(str ...string) string
- func (builder *Builder) BgBrightYellow(str ...string) string
- func (builder *Builder) BgCyan(str ...string) string
- func (builder *Builder) BgGray(str ...string) string
- func (builder *Builder) BgGreen(str ...string) string
- func (builder *Builder) BgGrey(str ...string) string
- func (builder *Builder) BgHex(hex string) ColorFn
- func (builder *Builder) BgMagenta(str ...string) string
- func (builder *Builder) BgRGB(r uint8, g uint8, b uint8) ColorFn
- func (builder *Builder) BgRed(str ...string) string
- func (builder *Builder) BgWhite(str ...string) string
- func (builder *Builder) BgYellow(str ...string) string
- func (builder *Builder) Black(str ...string) string
- func (builder *Builder) Blue(str ...string) string
- func (builder *Builder) Bold(str ...string) string
- func (builder *Builder) BrightBlack(str ...string) string
- func (builder *Builder) BrightBlue(str ...string) string
- func (builder *Builder) BrightCyan(str ...string) string
- func (builder *Builder) BrightGreen(str ...string) string
- func (builder *Builder) BrightMagenta(str ...string) string
- func (builder *Builder) BrightRed(str ...string) string
- func (builder *Builder) BrightWhite(str ...string) string
- func (builder *Builder) BrightYellow(str ...string) string
- func (builder *Builder) Cyan(str ...string) string
- func (builder *Builder) Dim(str ...string) string
- func (builder *Builder) GetLevel() ColorLevel
- func (builder *Builder) Gray(str ...string) string
- func (builder *Builder) Green(str ...string) string
- func (builder *Builder) Grey(str ...string) string
- func (builder *Builder) Hex(hex string) ColorFn
- func (builder *Builder) Hidden(str ...string) string
- func (builder *Builder) Inverse(str ...string) string
- func (builder *Builder) Italic(str ...string) string
- func (builder *Builder) Magenta(str ...string) string
- func (builder *Builder) Overline(str ...string) string
- func (builder *Builder) Paint(strs ...string) string
- func (builder *Builder) RGB(r uint8, g uint8, b uint8) ColorFn
- func (builder *Builder) Red(str ...string) string
- func (builder *Builder) Reset(str ...string) string
- func (builder *Builder) SetLevel(level ColorLevel)
- func (builder *Builder) Sprintf(format string, a ...interface{}) string
- func (builder *Builder) Strikethrough(str ...string) string
- func (builder *Builder) Style(styles ...string) (ColorFn, error)
- func (builder *Builder) StyleMust(styles ...string) ColorFn
- func (builder *Builder) Underline(str ...string) string
- func (builder *Builder) White(str ...string) string
- func (builder *Builder) WithAnsi(code uint8) *Builder
- func (builder *Builder) WithAnsi256(code uint8) *Builder
- func (builder *Builder) WithBgAnsi(code uint8) *Builder
- func (builder *Builder) WithBgAnsi256(code uint8) *Builder
- func (builder *Builder) WithBgBlack() *Builder
- func (builder *Builder) WithBgBlue() *Builder
- func (builder *Builder) WithBgBrightBlack() *Builder
- func (builder *Builder) WithBgBrightBlue() *Builder
- func (builder *Builder) WithBgBrightCyan() *Builder
- func (builder *Builder) WithBgBrightGreen() *Builder
- func (builder *Builder) WithBgBrightMagenta() *Builder
- func (builder *Builder) WithBgBrightRed() *Builder
- func (builder *Builder) WithBgBrightWhite() *Builder
- func (builder *Builder) WithBgBrightYellow() *Builder
- func (builder *Builder) WithBgCyan() *Builder
- func (builder *Builder) WithBgGray() *Builder
- func (builder *Builder) WithBgGreen() *Builder
- func (builder *Builder) WithBgGrey() *Builder
- func (builder *Builder) WithBgHex(hex string) *Builder
- func (builder *Builder) WithBgMagenta() *Builder
- func (builder *Builder) WithBgRGB(r uint8, g uint8, b uint8) *Builder
- func (builder *Builder) WithBgRed() *Builder
- func (builder *Builder) WithBgWhite() *Builder
- func (builder *Builder) WithBgYellow() *Builder
- func (builder *Builder) WithBlack() *Builder
- func (builder *Builder) WithBlue() *Builder
- func (builder *Builder) WithBold() *Builder
- func (builder *Builder) WithBrightBlack() *Builder
- func (builder *Builder) WithBrightBlue() *Builder
- func (builder *Builder) WithBrightCyan() *Builder
- func (builder *Builder) WithBrightGreen() *Builder
- func (builder *Builder) WithBrightMagenta() *Builder
- func (builder *Builder) WithBrightRed() *Builder
- func (builder *Builder) WithBrightWhite() *Builder
- func (builder *Builder) WithBrightYellow() *Builder
- func (builder *Builder) WithCyan() *Builder
- func (builder *Builder) WithDim() *Builder
- func (builder *Builder) WithGray() *Builder
- func (builder *Builder) WithGreen() *Builder
- func (builder *Builder) WithGrey() *Builder
- func (builder *Builder) WithHex(hex string) *Builder
- func (builder *Builder) WithHidden() *Builder
- func (builder *Builder) WithInverse() *Builder
- func (builder *Builder) WithItalic() *Builder
- func (builder *Builder) WithMagenta() *Builder
- func (builder *Builder) WithOverline() *Builder
- func (builder *Builder) WithRGB(r uint8, g uint8, b uint8) *Builder
- func (builder *Builder) WithRed() *Builder
- func (builder *Builder) WithReset() *Builder
- func (builder *Builder) WithStrikethrough() *Builder
- func (builder *Builder) WithStyle(styles ...string) (*Builder, error)
- func (builder *Builder) WithStyleMust(styles ...string) *Builder
- func (builder *Builder) WithUnderline() *Builder
- func (builder *Builder) WithWhite() *Builder
- func (builder *Builder) WithYellow() *Builder
- func (builder *Builder) Yellow(str ...string) string
- type ColorFn
- func Ansi(code uint8) ColorFn
- func Ansi256(code uint8) ColorFn
- func BgAnsi(code uint8) ColorFn
- func BgAnsi256(code uint8) ColorFn
- func BgHex(hex string) ColorFn
- func BgRGB(r uint8, g uint8, b uint8) ColorFn
- func Hex(hex string) ColorFn
- func RGB(r uint8, g uint8, b uint8) ColorFn
- func Style(styles ...string) (ColorFn, error)
- func StyleMust(styles ...string) ColorFn
- type ColorLevel
- type Option
Constants ¶
This section is empty.
Variables ¶
var Stderr = New( ForceLevel(ColorLevel(supportscolor.Stderr().Level)), )
Stderr is an instance of GChalk pre-configured for stderr. Use this when coloring strings you intend to write the stderr.
Functions ¶
func BgBrightBlack ¶
BgBrightBlack returns a string where the background color is BrightBlack.
func BgBrightBlue ¶
BgBrightBlue returns a string where the background color is BrightBlue.
func BgBrightCyan ¶
BgBrightCyan returns a string where the background color is BrightCyan.
func BgBrightGreen ¶
BgBrightGreen returns a string where the background color is BrightGreen.
func BgBrightMagenta ¶
BgBrightMagenta returns a string where the background color is BrightMagenta.
func BgBrightRed ¶
BgBrightRed returns a string where the background color is BrightRed.
func BgBrightWhite ¶
BgBrightWhite returns a string where the background color is BrightWhite.
func BgBrightYellow ¶
BgBrightYellow returns a string where the background color is BrightYellow.
func BrightBlack ¶
BrightBlack returns a string where the color is brightBlack.
func BrightBlue ¶
BrightBlue returns a string where the color is brightBlue.
func BrightCyan ¶
BrightCyan returns a string where the color is brightCyan.
func BrightGreen ¶
BrightGreen returns a string where the color is brightGreen.
func BrightMagenta ¶
BrightMagenta returns a string where the color is brightMagenta.
func BrightWhite ¶
BrightWhite returns a string where the color is brightWhite.
func BrightYellow ¶
BrightYellow returns a string where the color is brightYellow.
func SetLevel ¶
func SetLevel(level ColorLevel)
SetLevel is used to override the auto-detected color level.
func Strikethrough ¶
Strikethrough returns a string with the strikethrough modifier.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
A Builder is used to define and chain together styles.
Instances of Builder cannot be constructed directly - you can build a new instance via the New() function, which will give you an instance you can configure without modifying the "default" Builder.
func WithAnsi256 ¶
WithAnsi256 returns a Builder that generates strings with the specified color. Note that if ANSI 256 support is unavailable, this will automatically convert the color to the closest available color.
func WithBgAnsi ¶
WithBgAnsi returns a Builder that generates strings with the specified background color.
func WithBgAnsi256 ¶
WithBgAnsi256 returns a Builder that generates strings with the specified background color. Note that if ANSI 256 support is unavailable, this will automatically convert the color to the closest available color.
func WithBgBlack ¶
func WithBgBlack() *Builder
WithBgBlack returns a Builder that generates strings where the background color is Black, and further styles can be applied via chaining.
func WithBgBlue ¶
func WithBgBlue() *Builder
WithBgBlue returns a Builder that generates strings where the background color is Blue, and further styles can be applied via chaining.
func WithBgBrightBlack ¶
func WithBgBrightBlack() *Builder
WithBgBrightBlack returns a Builder that generates strings where the background color is BrightBlack, and further styles can be applied via chaining.
func WithBgBrightBlue ¶
func WithBgBrightBlue() *Builder
WithBgBrightBlue returns a Builder that generates strings where the background color is BrightBlue, and further styles can be applied via chaining.
func WithBgBrightCyan ¶
func WithBgBrightCyan() *Builder
WithBgBrightCyan returns a Builder that generates strings where the background color is BrightCyan, and further styles can be applied via chaining.
func WithBgBrightGreen ¶
func WithBgBrightGreen() *Builder
WithBgBrightGreen returns a Builder that generates strings where the background color is BrightGreen, and further styles can be applied via chaining.
func WithBgBrightMagenta ¶
func WithBgBrightMagenta() *Builder
WithBgBrightMagenta returns a Builder that generates strings where the background color is BrightMagenta, and further styles can be applied via chaining.
func WithBgBrightRed ¶
func WithBgBrightRed() *Builder
WithBgBrightRed returns a Builder that generates strings where the background color is BrightRed, and further styles can be applied via chaining.
func WithBgBrightWhite ¶
func WithBgBrightWhite() *Builder
WithBgBrightWhite returns a Builder that generates strings where the background color is BrightWhite, and further styles can be applied via chaining.
func WithBgBrightYellow ¶
func WithBgBrightYellow() *Builder
WithBgBrightYellow returns a Builder that generates strings where the background color is BrightYellow, and further styles can be applied via chaining.
func WithBgCyan ¶
func WithBgCyan() *Builder
WithBgCyan returns a Builder that generates strings where the background color is Cyan, and further styles can be applied via chaining.
func WithBgGray ¶
func WithBgGray() *Builder
WithBgGray returns a Builder that generates strings where the background color is Gray, and further styles can be applied via chaining.
func WithBgGreen ¶
func WithBgGreen() *Builder
WithBgGreen returns a Builder that generates strings where the background color is Green, and further styles can be applied via chaining.
func WithBgGrey ¶
func WithBgGrey() *Builder
WithBgGrey returns a Builder that generates strings where the background color is Grey, and further styles can be applied via chaining.
func WithBgHex ¶
WithBgHex returns a Builder that generates strings with the specified background color. Note that if true color support is unavailable, this will automatically convert the color to the closest available color.
func WithBgMagenta ¶
func WithBgMagenta() *Builder
WithBgMagenta returns a Builder that generates strings where the background color is Magenta, and further styles can be applied via chaining.
func WithBgRGB ¶
WithBgRGB returns a Builder that generates strings with the specified background color. Note that if true color support is unavailable, this will automatically convert the color to the closest available color.
func WithBgRed ¶
func WithBgRed() *Builder
WithBgRed returns a Builder that generates strings where the background color is Red, and further styles can be applied via chaining.
func WithBgWhite ¶
func WithBgWhite() *Builder
WithBgWhite returns a Builder that generates strings where the background color is White, and further styles can be applied via chaining.
func WithBgYellow ¶
func WithBgYellow() *Builder
WithBgYellow returns a Builder that generates strings where the background color is Yellow, and further styles can be applied via chaining.
func WithBlack ¶
func WithBlack() *Builder
WithBlack returns a Builder that generates strings where the color is black, and further styles can be applied via chaining.
func WithBlue ¶
func WithBlue() *Builder
WithBlue returns a Builder that generates strings where the color is blue, and further styles can be applied via chaining.
func WithBold ¶
func WithBold() *Builder
WithBold returns a Builder that generates strings with the bold modifier, and further styles can be applied via chaining.
func WithBrightBlack ¶
func WithBrightBlack() *Builder
WithBrightBlack returns a Builder that generates strings where the color is brightBlack, and further styles can be applied via chaining.
func WithBrightBlue ¶
func WithBrightBlue() *Builder
WithBrightBlue returns a Builder that generates strings where the color is brightBlue, and further styles can be applied via chaining.
func WithBrightCyan ¶
func WithBrightCyan() *Builder
WithBrightCyan returns a Builder that generates strings where the color is brightCyan, and further styles can be applied via chaining.
func WithBrightGreen ¶
func WithBrightGreen() *Builder
WithBrightGreen returns a Builder that generates strings where the color is brightGreen, and further styles can be applied via chaining.
func WithBrightMagenta ¶
func WithBrightMagenta() *Builder
WithBrightMagenta returns a Builder that generates strings where the color is brightMagenta, and further styles can be applied via chaining.
func WithBrightRed ¶
func WithBrightRed() *Builder
WithBrightRed returns a Builder that generates strings where the color is brightRed, and further styles can be applied via chaining.
func WithBrightWhite ¶
func WithBrightWhite() *Builder
WithBrightWhite returns a Builder that generates strings where the color is brightWhite, and further styles can be applied via chaining.
func WithBrightYellow ¶
func WithBrightYellow() *Builder
WithBrightYellow returns a Builder that generates strings where the color is brightYellow, and further styles can be applied via chaining.
func WithCyan ¶
func WithCyan() *Builder
WithCyan returns a Builder that generates strings where the color is cyan, and further styles can be applied via chaining.
func WithDim ¶
func WithDim() *Builder
WithDim returns a Builder that generates strings with the dim modifier, and further styles can be applied via chaining.
func WithGray ¶
func WithGray() *Builder
WithGray returns a Builder that generates strings where the color is gray, and further styles can be applied via chaining.
func WithGreen ¶
func WithGreen() *Builder
WithGreen returns a Builder that generates strings where the color is green, and further styles can be applied via chaining.
func WithGrey ¶
func WithGrey() *Builder
WithGrey returns a Builder that generates strings where the color is grey, and further styles can be applied via chaining.
func WithHex ¶
WithHex returns a Builder that generates strings with the specified color. Note that if true color support is unavailable, this will automatically convert the color to the closest available color.
func WithHidden ¶
func WithHidden() *Builder
WithHidden returns a Builder that generates strings with the hidden modifier, and further styles can be applied via chaining.
func WithInverse ¶
func WithInverse() *Builder
WithInverse returns a Builder that generates strings with the inverse modifier, and further styles can be applied via chaining.
func WithItalic ¶
func WithItalic() *Builder
WithItalic returns a Builder that generates strings with the italic modifier, and further styles can be applied via chaining.
func WithMagenta ¶
func WithMagenta() *Builder
WithMagenta returns a Builder that generates strings where the color is magenta, and further styles can be applied via chaining.
func WithOverline ¶
func WithOverline() *Builder
WithOverline returns a Builder that generates strings with the overline modifier, and further styles can be applied via chaining.
func WithRGB ¶
WithRGB returns a Builder that generates strings with the specified color. Note that if true color support is unavailable, this will automatically convert the color to the closest available color.
func WithRed ¶
func WithRed() *Builder
WithRed returns a Builder that generates strings where the color is red, and further styles can be applied via chaining.
func WithReset ¶
func WithReset() *Builder
WithReset returns a Builder that generates strings with the reset modifier, and further styles can be applied via chaining.
func WithStrikethrough ¶
func WithStrikethrough() *Builder
WithStrikethrough returns a Builder that generates strings with the strikethrough modifier, and further styles can be applied via chaining.
func WithStyle ¶
WithStyle will construct a Builder that generates strings with the specified styles. Styles can be specified as a named style (e.g. "red", "bgRed", "bgred"), or as a hex color ("#ff00ff" or "bg#ff00ff"). If the style cannot be parsed, this will return an error.
func WithStyleMust ¶
WithStyleMust will construct a Builder that generates strings with the specified styles. Styles can be specified as a named style (e.g. "red", "bgRed", "bgred"), or as a hex color ("#ff00ff" or "bg#ff00ff"). If the style cannot be parsed, this will panic.
func WithUnderline ¶
func WithUnderline() *Builder
WithUnderline returns a Builder that generates strings with the underline modifier, and further styles can be applied via chaining.
func WithWhite ¶
func WithWhite() *Builder
WithWhite returns a Builder that generates strings where the color is white, and further styles can be applied via chaining.
func WithYellow ¶
func WithYellow() *Builder
WithYellow returns a Builder that generates strings where the color is yellow, and further styles can be applied via chaining.
func (*Builder) Ansi ¶
Ansi returns a function which colors a string using the ANSI 16 color pallette.
func (*Builder) Ansi256 ¶
Ansi256 returns a function which colors a string using the ANSI 256 color pallette. If ANSI 256 color support is unavailable, this will automatically convert the color to the closest available color.
func (*Builder) BgAnsi ¶
BgAnsi returns a function which colors the background of a string using the ANSI 16 color pallette.
func (*Builder) BgAnsi256 ¶
BgAnsi256 returns a function which colors the background of a string using the ANSI 256 color pallette. If ANSI 256 color support is unavailable, this will automatically convert the color to the closest available color.
func (*Builder) BgBlack ¶
BgBlack returns a string where the background color is Black, in addition to other styles from this builder.
func (*Builder) BgBlue ¶
BgBlue returns a string where the background color is Blue, in addition to other styles from this builder.
func (*Builder) BgBrightBlack ¶
BgBrightBlack returns a string where the background color is BrightBlack, in addition to other styles from this builder.
func (*Builder) BgBrightBlue ¶
BgBrightBlue returns a string where the background color is BrightBlue, in addition to other styles from this builder.
func (*Builder) BgBrightCyan ¶
BgBrightCyan returns a string where the background color is BrightCyan, in addition to other styles from this builder.
func (*Builder) BgBrightGreen ¶
BgBrightGreen returns a string where the background color is BrightGreen, in addition to other styles from this builder.
func (*Builder) BgBrightMagenta ¶
BgBrightMagenta returns a string where the background color is BrightMagenta, in addition to other styles from this builder.
func (*Builder) BgBrightRed ¶
BgBrightRed returns a string where the background color is BrightRed, in addition to other styles from this builder.
func (*Builder) BgBrightWhite ¶
BgBrightWhite returns a string where the background color is BrightWhite, in addition to other styles from this builder.
func (*Builder) BgBrightYellow ¶
BgBrightYellow returns a string where the background color is BrightYellow, in addition to other styles from this builder.
func (*Builder) BgCyan ¶
BgCyan returns a string where the background color is Cyan, in addition to other styles from this builder.
func (*Builder) BgGray ¶
BgGray returns a string where the background color is Gray, in addition to other styles from this builder.
func (*Builder) BgGreen ¶
BgGreen returns a string where the background color is Green, in addition to other styles from this builder.
func (*Builder) BgGrey ¶
BgGrey returns a string where the background color is Grey, in addition to other styles from this builder.
func (*Builder) BgHex ¶
BgHex returns a function which colors the background of a string using true color support, from a hexadecimal color string (e.g. "#FF00FF" or "#FFF"). If true color support is unavailable, this will automatically convert the color to the closest available color.
func (*Builder) BgMagenta ¶
BgMagenta returns a string where the background color is Magenta, in addition to other styles from this builder.
func (*Builder) BgRGB ¶
BgRGB returns a function which colors the background of a string using true color support. Note that if true color support is unavailable, this will automatically convert the color to the closest available color.
func (*Builder) BgRed ¶
BgRed returns a string where the background color is Red, in addition to other styles from this builder.
func (*Builder) BgWhite ¶
BgWhite returns a string where the background color is White, in addition to other styles from this builder.
func (*Builder) BgYellow ¶
BgYellow returns a string where the background color is Yellow, in addition to other styles from this builder.
func (*Builder) Black ¶
Black returns a string where the color is black, in addition to other styles from this builder.
func (*Builder) Blue ¶
Blue returns a string where the color is blue, in addition to other styles from this builder.
func (*Builder) Bold ¶
Bold returns a string with the bold modifier, in addition to other styles from this builder.
func (*Builder) BrightBlack ¶
BrightBlack returns a string where the color is brightBlack, in addition to other styles from this builder.
func (*Builder) BrightBlue ¶
BrightBlue returns a string where the color is brightBlue, in addition to other styles from this builder.
func (*Builder) BrightCyan ¶
BrightCyan returns a string where the color is brightCyan, in addition to other styles from this builder.
func (*Builder) BrightGreen ¶
BrightGreen returns a string where the color is brightGreen, in addition to other styles from this builder.
func (*Builder) BrightMagenta ¶
BrightMagenta returns a string where the color is brightMagenta, in addition to other styles from this builder.
func (*Builder) BrightRed ¶
BrightRed returns a string where the color is brightRed, in addition to other styles from this builder.
func (*Builder) BrightWhite ¶
BrightWhite returns a string where the color is brightWhite, in addition to other styles from this builder.
func (*Builder) BrightYellow ¶
BrightYellow returns a string where the color is brightYellow, in addition to other styles from this builder.
func (*Builder) Cyan ¶
Cyan returns a string where the color is cyan, in addition to other styles from this builder.
func (*Builder) Dim ¶
Dim returns a string with the dim modifier, in addition to other styles from this builder.
func (*Builder) GetLevel ¶
func (builder *Builder) GetLevel() ColorLevel
GetLevel returns the currently configured level for this builder.
func (*Builder) Gray ¶
Gray returns a string where the color is gray, in addition to other styles from this builder.
func (*Builder) Green ¶
Green returns a string where the color is green, in addition to other styles from this builder.
func (*Builder) Grey ¶
Grey returns a string where the color is grey, in addition to other styles from this builder.
func (*Builder) Hex ¶
Hex returns a function which colors a string using true color support, from a hexadecimal color string (e.g. "#FF00FF" or "#FFF"). If true color support is unavailable, this will automatically convert the color to the closest available color.
func (*Builder) Hidden ¶
Hidden returns a string with the hidden modifier, in addition to other styles from this builder.
func (*Builder) Inverse ¶
Inverse returns a string with the inverse modifier, in addition to other styles from this builder.
func (*Builder) Italic ¶
Italic returns a string with the italic modifier, in addition to other styles from this builder.
func (*Builder) Magenta ¶
Magenta returns a string where the color is magenta, in addition to other styles from this builder.
func (*Builder) Overline ¶
Overline returns a string with the overline modifier, in addition to other styles from this builder.
func (*Builder) Paint ¶
Paint will apply a style to a string. This is similar to the `paint()` function from Rust's `ansi_term` crate.
gchalk.WithRed().Paint("Hello World!")
func (*Builder) RGB ¶
RGB returns a function which colors a string using true color support. Note that if true color support is unavailable, this will automatically convert the color to the closest available color.
func (*Builder) Red ¶
Red returns a string where the color is red, in addition to other styles from this builder.
func (*Builder) Reset ¶
Reset returns a string with the reset modifier, in addition to other styles from this builder.
func (*Builder) SetLevel ¶
func (builder *Builder) SetLevel(level ColorLevel)
SetLevel is used to override the auto-detected color level for a builder. Calling this at any level of the builder will affect the entire instance of the builder.
func (*Builder) Sprintf ¶
Sprintf is a convenience function for coloring formatted strings.
gchalk.WithRed().Sprtinf("Hello %s", "World!")
func (*Builder) Strikethrough ¶
Strikethrough returns a string with the strikethrough modifier, in addition to other styles from this builder.
func (*Builder) Style ¶
Style will return a function which colors a string with the specified styles. Styles can be specified as a named style (e.g. "red", "bgRed", "bgred"), or as a hex color ("#ff00ff" or "bg#ff00ff"). If the style cannot be parsed, this will return an error.
func (*Builder) StyleMust ¶
StyleMust will return a function which colors a string with the specified styles. Styles can be specified as a named style (e.g. "red", "bgRed", "bgred"), or as a hex color ("#ff00ff" or "bg#ff00ff"). If the style cannot be parsed, this will panic.
func (*Builder) Underline ¶
Underline returns a string with the underline modifier, in addition to other styles from this builder.
func (*Builder) White ¶
White returns a string where the color is white, in addition to other styles from this builder.
func (*Builder) WithAnsi ¶
WithAnsi returns a Builder that generates strings with the specified color.
func (*Builder) WithAnsi256 ¶
WithAnsi256 returns a Builder that generates strings with the specified color. Note that if ANSI 256 support is unavailable, this will automatically convert the color to the closest available color.
func (*Builder) WithBgAnsi ¶
WithBgAnsi returns a Builder that generates strings with the specified background color.
func (*Builder) WithBgAnsi256 ¶
WithBgAnsi256 returns a Builder that generates strings with the specified background color. Note that if ANSI 256 support is unavailable, this will automatically convert the color to the closest available color.
func (*Builder) WithBgBlack ¶
WithBgBlack returns a Builder that generates strings where the background color is Black, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBgBlue ¶
WithBgBlue returns a Builder that generates strings where the background color is Blue, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBgBrightBlack ¶
WithBgBrightBlack returns a Builder that generates strings where the background color is BrightBlack, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBgBrightBlue ¶
WithBgBrightBlue returns a Builder that generates strings where the background color is BrightBlue, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBgBrightCyan ¶
WithBgBrightCyan returns a Builder that generates strings where the background color is BrightCyan, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBgBrightGreen ¶
WithBgBrightGreen returns a Builder that generates strings where the background color is BrightGreen, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBgBrightMagenta ¶
WithBgBrightMagenta returns a Builder that generates strings where the background color is BrightMagenta, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBgBrightRed ¶
WithBgBrightRed returns a Builder that generates strings where the background color is BrightRed, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBgBrightWhite ¶
WithBgBrightWhite returns a Builder that generates strings where the background color is BrightWhite, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBgBrightYellow ¶
WithBgBrightYellow returns a Builder that generates strings where the background color is BrightYellow, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBgCyan ¶
WithBgCyan returns a Builder that generates strings where the background color is Cyan, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBgGray ¶
WithBgGray returns a Builder that generates strings where the background color is Gray, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBgGreen ¶
WithBgGreen returns a Builder that generates strings where the background color is Green, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBgGrey ¶
WithBgGrey returns a Builder that generates strings where the background color is Grey, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBgHex ¶
WithBgHex returns a Builder that generates strings with the specified background color. Note that if true color support is unavailable, this will automatically convert the color to the closest available color.
func (*Builder) WithBgMagenta ¶
WithBgMagenta returns a Builder that generates strings where the background color is Magenta, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBgRGB ¶
WithBgRGB returns a Builder that generates strings with the specified background color. Note that if true color support is unavailable, this will automatically convert the color to the closest available color.
func (*Builder) WithBgRed ¶
WithBgRed returns a Builder that generates strings where the background color is Red, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBgWhite ¶
WithBgWhite returns a Builder that generates strings where the background color is White, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBgYellow ¶
WithBgYellow returns a Builder that generates strings where the background color is Yellow, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBlack ¶
WithBlack returns a Builder that generates strings where the color is black, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBlue ¶
WithBlue returns a Builder that generates strings where the color is blue, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBold ¶
WithBold returns a Builder that generates strings with the bold modifier, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBrightBlack ¶
WithBrightBlack returns a Builder that generates strings where the color is brightBlack, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBrightBlue ¶
WithBrightBlue returns a Builder that generates strings where the color is brightBlue, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBrightCyan ¶
WithBrightCyan returns a Builder that generates strings where the color is brightCyan, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBrightGreen ¶
WithBrightGreen returns a Builder that generates strings where the color is brightGreen, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBrightMagenta ¶
WithBrightMagenta returns a Builder that generates strings where the color is brightMagenta, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBrightRed ¶
WithBrightRed returns a Builder that generates strings where the color is brightRed, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBrightWhite ¶
WithBrightWhite returns a Builder that generates strings where the color is brightWhite, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithBrightYellow ¶
WithBrightYellow returns a Builder that generates strings where the color is brightYellow, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithCyan ¶
WithCyan returns a Builder that generates strings where the color is cyan, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithDim ¶
WithDim returns a Builder that generates strings with the dim modifier, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithGray ¶
WithGray returns a Builder that generates strings where the color is gray, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithGreen ¶
WithGreen returns a Builder that generates strings where the color is green, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithGrey ¶
WithGrey returns a Builder that generates strings where the color is grey, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithHex ¶
WithHex returns a Builder that generates strings with the specified color. Note that if true color support is unavailable, this will automatically convert the color to the closest available color.
func (*Builder) WithHidden ¶
WithHidden returns a Builder that generates strings with the hidden modifier, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithInverse ¶
WithInverse returns a Builder that generates strings with the inverse modifier, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithItalic ¶
WithItalic returns a Builder that generates strings with the italic modifier, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithMagenta ¶
WithMagenta returns a Builder that generates strings where the color is magenta, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithOverline ¶
WithOverline returns a Builder that generates strings with the overline modifier, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithRGB ¶
WithRGB returns a Builder that generates strings with the specified color. Note that if true color support is unavailable, this will automatically convert the color to the closest available color.
func (*Builder) WithRed ¶
WithRed returns a Builder that generates strings where the color is red, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithReset ¶
WithReset returns a Builder that generates strings with the reset modifier, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithStrikethrough ¶
WithStrikethrough returns a Builder that generates strings with the strikethrough modifier, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithStyle ¶
WithStyle will construct a Builder that generates strings with the specified styles. Styles can be specified as a named style (e.g. "red", "bgRed", "bgred"), or as a hex color ("#ff00ff" or "bg#ff00ff"). If the style cannot be parsed, this will return an error.
func (*Builder) WithStyleMust ¶
WithStyleMust will construct a Builder that generates strings with the specified styles. Styles can be specified as a named style (e.g. "red", "bgRed", "bgred"), or as a hex color ("#ff00ff" or "bg#ff00ff"). If the style cannot be parsed, this will panic.
func (*Builder) WithUnderline ¶
WithUnderline returns a Builder that generates strings with the underline modifier, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithWhite ¶
WithWhite returns a Builder that generates strings where the color is white, in addition to other styles from this builder, and further styles can be applied via chaining.
func (*Builder) WithYellow ¶
WithYellow returns a Builder that generates strings where the color is yellow, in addition to other styles from this builder, and further styles can be applied via chaining.
type ColorFn ¶ added in v1.3.0
ColorFn is a convenience type for a function that takes in a string and returns a colored string.
func Ansi256 ¶
Ansi256 returns a function which colors a string using the ANSI 256 color pallette. If ANSI 256 color support is unavailable, this will automatically convert the color to the closest available color.
func BgAnsi ¶
BgAnsi returns a function which colors the background of a string using the ANSI 16 color pallette.
func BgAnsi256 ¶
BgAnsi256 returns a function which colors the background of a string using the ANSI 256 color pallette. If ANSI 256 color support is unavailable, this will automatically convert the color to the closest available color.
func BgHex ¶
BgHex returns a function which colors the background of a string using true color support, from a hexadecimal color string (e.g. "#FF00FF" or "#FFF"). If true color support is unavailable, this will automatically convert the color to the closest available color.
func BgRGB ¶
BgRGB returns a function which colors the background of a string using true color support. Note that if true color support is unavailable, this will automatically convert the color to the closest available color.
func Hex ¶
Hex returns a function which colors a string using true color support, from a hexadecimal color string (e.g. "#FF00FF" or "#FFF"). If true color support is unavailable, this will automatically convert the color to the closest available color.
func RGB ¶
RGB returns a function which colors a string using true color support. Note that if true color support is unavailable, this will automatically convert the color to the closest available color.
func Style ¶
Style will return a function which colors a string with the specified styles. Styles can be specified as a named style (e.g. "red", "bgRed", "bgred"), or as a hex color ("#ff00ff" or "bg#ff00ff"). If the style cannot be parsed, this will return an error.
type ColorLevel ¶
type ColorLevel = supportscolor.ColorLevel
ColorLevel represents the ANSI color level supported by the terminal.
const ( // LevelNone represents a terminal that does not support color at all. LevelNone ColorLevel = supportscolor.None // LevelBasic represents a terminal with basic 16 color support. LevelBasic ColorLevel = supportscolor.Basic // LevelAnsi256 represents a terminal with 256 color support. LevelAnsi256 ColorLevel = supportscolor.Ansi256 // LevelAnsi16m represents a terminal with full true color support. LevelAnsi16m ColorLevel = supportscolor.Ansi16m )
type Option ¶
type Option func(*Builder)
An Option which can be passed to `New()`.
func ForceLevel ¶
func ForceLevel(level ColorLevel) Option
ForceLevel is an option that can be passed to `New` to force the color level used.
Directories ¶
Path | Synopsis |
---|---|
pkg
|
|
ansistyles
Package ansistyles is a complete port of the "ansi-styles" node.js library.
|
Package ansistyles is a complete port of the "ansi-styles" node.js library. |