gchalk

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: MIT Imports: 6 Imported by: 118

README

GChalk

PkgGoDev Build Status Go Report Card Release

GChalk is a library heavily inspired by chalk, the popular Node.js terminal color library, and using go ports of supports-color and ansi-styles.

Features

Feature Comparison

Feature gchalk termenv aurora fatih/color mgutz/ansi
TTY Detection ✅ (1) ✅ (1)
Color Detection
Windows 10 ✅ (5) ✅ (2)
Nested Styles ? (6) ✅ (3)
256 Color Support ✅ (4) ✅ (4)
16.7m Color Support
Speed 70ns 330ns 196ns 420ns 40ns
  1. fatih/color and termenv support automatic TTY detection, but assume that if stdout is not a TTY, then stderr is also not a TTY, which may not be true.
  2. fatih/color supports Windows 10, but you need to write to a special stream.
  3. aurora supports nested styles via its custom Sprintf(), but you can't convert things to a string first - need to keep everything as aurora Values.
  4. aurora and mgutz/ansi both support 256 color output, but they don't detect whether the terminal supports it or not, and won't automatically convert 256 color output to 16 color output if it doesn't.
  5. termenv assumes Windows always supports 16.7m colors, which might cause problems on really old Windows 10 builds. termenv also does not enable ANSI support on Windows 10, so users not using Windows Terminal may have to take extra steps to enable ANSI support (although this is done for you if you are using the related library LipGloss).
  6. termenv claims to support nested styles, but I couldn't figure out how to make them work.

Install

go get github.com/jwalton/gchalk

Usage

package main

import (
    "fmt"
    "github.com/jwalton/gchalk"
)

func main() {
    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.

GChalk uses a chainable syntax for composing styles together, which should be instantly familiar if you've ever used chalk or similar libraries. To style a string blue, for example, you"d call gchalk.Blue("hello"). To style it blue with a red background, you can use gchalk.WithBgRed().Blue("hello").

// 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!"))

// Use color name strings
fmt.Println(gchalk.StyleMust("blue")("Hello World!"))


// Write to stderr:
os.Stderr.WriteString(gchalk.Stderr.Red("Ohs noes!\n"))

You can easily define your own themes:

var error = gchalk.WithBold().Red
var warning = gchalk.Yellow

fmt.Println(error("Error!"))
fmt.Println(warning("Warning!"))

API

gchalk[.With<style>][.with<style>...].<style>(string [, string...])

Example:

fmt.Println(gchalk.WithRed().WithBold().Underline("Hello", "world"))

Chain styles and call the last one as a method with a string argument. Order doesn't matter, and later styles take precedent in case of a conflict. Multiple arguments will be separated by a space.

You can also obtain a Builder instance and then use the Paint() function, similar to Rust's ansi_term crate, or use the Sprintf() convenience function:

fmt.Println(gchalk.WithRed().Paint("Hello", "world"))
fmt.Println(gchalk.WithRed().Sprintf("Hello %v", "world"))
gchalk.Style(style [, style...])(string [, string...])

Example:

styler, err := gchalk.Style("bold", "red")
if err == nil {
    fmt.Println(styler("This is bold and red"))
}

fmt.Println(gchalk.StyleMust("bold", "red")("This is also bold and red."))

Style and StyleMust allow styling a string based on the case-insensitive names of colors and modifiers. There's also a WithStyle and WithStyleMust for chaining named styles with other styles. These funcions can also accept hex codes or bg#000000 hex codes for background colors.

gchalk.SetLevel(level) and gchalk.GetLevel()

Specifies the level of color support. See the section on color detection for details about how gchalk auto-detects color support. You can override the detected level by calling SetLevel(). You should however only do this in your own application, as it applies globally to all gchalk consumers. If you need to change this in a library, create a new instance:

var myGChalk = gchalk.New(gchalk.ForceLevel(gchalk.LevelNone))
Level Description
LevelNone = 0 All colors disabled
LevelBasic = 1 Basic color support (16 colors)
LevelAnsi256 = 2 256 color support
LevelAnsi16m = 3 Truecolor support (16 million colors)
gchalk.Stderr

gchalk.Stderr contains a separate instance configured with color support detected for stderr stream instead of stdout.

Stdout and stderr can be different in cases where the user is piping output. For example, if a user runs:

myprogram > out.txt

then stdout will not be a TTY, so by default gchalk will not emit any color, however stderr will be a TTY, so gchalk.Stderr.Red(...) will still generate colored output.

gchalk.New(options...)

Creates a new instance of gchalk. Options include:

  • gchalk.ForceLevel(level) - Force the color level. If not specified, will be autodetected from stdout.

Styles

Modifiers
  • Reset - Resets the current color chain.
  • Bold - Make text bold.
  • Dim - Emitting only a small amount of light.
  • Italic - Make text italic. (Not widely supported)
  • Underline - Make text underline. (Not widely supported)
  • Inverse- Inverse background and foreground colors.
  • Hidden - Prints the text, but makes it invisible.
  • Strikethrough - Puts a horizontal line through the center of the text. (Not widely supported)
  • Visible- Prints the text only when gchalk has a color level > 0. Can be useful for things that are purely cosmetic.
Colors
  • Black
  • Red
  • Green
  • Yellow
  • Blue
  • Magenta
  • Cyan
  • White
  • BrightBlack (alias: gray, grey)
  • BrightRed
  • BrightGreen
  • BrightYellow
  • BrightBlue
  • BrightMagenta
  • BrightCyan
  • BrightWhite
Background colors
  • BgBlack
  • BgRed
  • BgGreen
  • BgYellow
  • BgBlue
  • BgMagenta
  • BgCyan
  • BgWhite
  • BgBrightBlack (alias: BgGray, BgGrey)
  • BgBrightRed
  • BgBrightGreen
  • BgBrightYellow
  • BgBrightBlue
  • BgBrightMagenta
  • BgBrightCyan
  • BgBrightWhite

256 and Truecolor color support

GChalk supports 256 colors and Truecolor (16 million colors) on supported terminal apps, including Windows 10.

Colors are downsampled from 16 million RGB values to an ANSI color format that is supported by the terminal emulator (or by specifying {level: n} as a Chalk option). For example, GChalk configured to run at level 1 (basic color support) will downsample an RGB value of #FF0000 (red) to 91 (ANSI escape for bright-red).

Examples:

  • gchalk.WithHex('#DEADED').Underline('Hello, world!')
  • gchalk.WithRGB(15, 100, 204).Inverse('Hello!')

Background versions of these models are prefixed with Bg and the first level of the module capitalized:

  • gchalk.WithBgHex('#DEADED').Underline('Hello, world!')
  • gchalk.WithBgRgb(15, 100, 204).Unverse('Hello!')

The following color models can be used:

  • rgb - Example: gchalk.RGB(255, 136, 0)('Orange!')
  • hex - Example: gchalk.Hex('#FF8800')('Orange!')
  • ansi256 - Example: gchalk.BgAnsi256(194)('Honeydew, more or less')
  • ansi - Example: gchalk.WithAnsi(31).BgAnsi(93)('red on bright yellow')

Windows 10 Support

GChalk is cross-platform, and will work on Linux and MacOS systems, but will also work on Windows 10, and without the need for writing to a special stream or using ansicon.

Many ANSI color libraries for Go do a poor job of handling colors in Windows. This is because historically, Windows has not supported ANSI color codes, so hacks like ansicon or go-colorable were required. However, Windows 10 has supported ANSI escape codes since 2017 (build 10586 for 256 color support, and build 14931 for 16.7 million true color support). In Windows Terminal this is enabled by default, but in CMD.EXE or PowerShell, ANSI support must be enabled via ENABLE_VIRTUAL_TERMINAL_PROCESSING. GChalk, of course, takes care of all of this for you. This functionality is also availabile in the supportscolor library if you're an ANSI library author and you'd like to add this functionality to your own project.

Color Detection

Color support is automatically detected using supportscolor, and flags and command line arguments supported by supportscolor are also supported here. GChalk will automatically obey all the recommendations from Command Line Interface Guidelines. The following will disable color:

  • stdout is not a TTY. (Or, for gchalk.Stderr, stderr is not a TTY.)
  • The NO_COLOR environment variable is set.
  • The TERM variable has the value dumb.
  • The user passes the option --no-color, --no-colors, --color=false, or --color=never.
  • The FORCE_COLOR environment variable is 0.

Color support will be forcefully enabled if:

  • The FORCE_COLOR environment variable is set to 1, 2, or 3 (for 16 color, 256 color, and 16.7m color support, respectively).
  • The FORCE_COLOR environment variable is set with no value, or with true.
  • The uses passes the option --color, --colors, --color=true, or --color=always.

GChalk will also support colored output when run from popular CI environments, including Travis, CircleCI, Appveyor, GitlabCI, GitHub Actions, Buildkite, Drone, and TeamCity.

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

Constants

This section is empty.

Variables

View Source
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 BgBlack

func BgBlack(str ...string) string

BgBlack returns a string where the background color is Black.

func BgBlue

func BgBlue(str ...string) string

BgBlue returns a string where the background color is Blue.

func BgBrightBlack

func BgBrightBlack(str ...string) string

BgBrightBlack returns a string where the background color is BrightBlack.

func BgBrightBlue

func BgBrightBlue(str ...string) string

BgBrightBlue returns a string where the background color is BrightBlue.

func BgBrightCyan

func BgBrightCyan(str ...string) string

BgBrightCyan returns a string where the background color is BrightCyan.

func BgBrightGreen

func BgBrightGreen(str ...string) string

BgBrightGreen returns a string where the background color is BrightGreen.

func BgBrightMagenta

func BgBrightMagenta(str ...string) string

BgBrightMagenta returns a string where the background color is BrightMagenta.

func BgBrightRed

func BgBrightRed(str ...string) string

BgBrightRed returns a string where the background color is BrightRed.

func BgBrightWhite

func BgBrightWhite(str ...string) string

BgBrightWhite returns a string where the background color is BrightWhite.

func BgBrightYellow

func BgBrightYellow(str ...string) string

BgBrightYellow returns a string where the background color is BrightYellow.

func BgCyan

func BgCyan(str ...string) string

BgCyan returns a string where the background color is Cyan.

func BgGray

func BgGray(str ...string) string

BgGray returns a string where the background color is Gray.

func BgGreen

func BgGreen(str ...string) string

BgGreen returns a string where the background color is Green.

func BgGrey

func BgGrey(str ...string) string

BgGrey returns a string where the background color is Grey.

func BgMagenta

func BgMagenta(str ...string) string

BgMagenta returns a string where the background color is Magenta.

func BgRed

func BgRed(str ...string) string

BgRed returns a string where the background color is Red.

func BgWhite

func BgWhite(str ...string) string

BgWhite returns a string where the background color is White.

func BgYellow

func BgYellow(str ...string) string

BgYellow returns a string where the background color is Yellow.

func Black

func Black(str ...string) string

Black returns a string where the color is black.

func Blue

func Blue(str ...string) string

Blue returns a string where the color is blue.

func Bold

func Bold(str ...string) string

Bold returns a string with the bold modifier.

func BrightBlack

func BrightBlack(str ...string) string

BrightBlack returns a string where the color is brightBlack.

func BrightBlue

func BrightBlue(str ...string) string

BrightBlue returns a string where the color is brightBlue.

func BrightCyan

func BrightCyan(str ...string) string

BrightCyan returns a string where the color is brightCyan.

func BrightGreen

func BrightGreen(str ...string) string

BrightGreen returns a string where the color is brightGreen.

func BrightMagenta

func BrightMagenta(str ...string) string

BrightMagenta returns a string where the color is brightMagenta.

func BrightRed

func BrightRed(str ...string) string

BrightRed returns a string where the color is brightRed.

func BrightWhite

func BrightWhite(str ...string) string

BrightWhite returns a string where the color is brightWhite.

func BrightYellow

func BrightYellow(str ...string) string

BrightYellow returns a string where the color is brightYellow.

func Cyan

func Cyan(str ...string) string

Cyan returns a string where the color is cyan.

func Dim

func Dim(str ...string) string

Dim returns a string with the dim modifier.

func Gray

func Gray(str ...string) string

Gray returns a string where the color is gray.

func Green

func Green(str ...string) string

Green returns a string where the color is green.

func Grey

func Grey(str ...string) string

Grey returns a string where the color is grey.

func Hidden

func Hidden(str ...string) string

Hidden returns a string with the hidden modifier.

func Inverse

func Inverse(str ...string) string

Inverse returns a string with the inverse modifier.

func Italic

func Italic(str ...string) string

Italic returns a string with the italic modifier.

func Magenta

func Magenta(str ...string) string

Magenta returns a string where the color is magenta.

func Overline

func Overline(str ...string) string

Overline returns a string with the overline modifier.

func Red

func Red(str ...string) string

Red returns a string where the color is red.

func Reset

func Reset(str ...string) string

Reset returns a string with the reset modifier.

func SetLevel

func SetLevel(level ColorLevel)

SetLevel is used to override the auto-detected color level.

func Strikethrough

func Strikethrough(str ...string) string

Strikethrough returns a string with the strikethrough modifier.

func Underline

func Underline(str ...string) string

Underline returns a string with the underline modifier.

func White

func White(str ...string) string

White returns a string where the color is white.

func Yellow

func Yellow(str ...string) string

Yellow returns a string where the color is yellow.

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 New

func New(options ...Option) *Builder

New creates a new instance of GChalk.

func WithAnsi

func WithAnsi(code uint8) *Builder

WithAnsi returns a Builder that generates strings with the specified color.

func WithAnsi256

func WithAnsi256(code uint8) *Builder

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

func WithBgAnsi(code uint8) *Builder

WithBgAnsi returns a Builder that generates strings with the specified background color.

func WithBgAnsi256

func WithBgAnsi256(code uint8) *Builder

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

func WithBgHex(hex string) *Builder

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

func WithBgRGB(r uint8, g uint8, b uint8) *Builder

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

func WithHex(hex string) *Builder

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

func WithRGB(r uint8, g uint8, b uint8) *Builder

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

func WithStyle(styles ...string) (*Builder, error)

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

func WithStyleMust(styles ...string) *Builder

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

func (builder *Builder) Ansi(code uint8) ColorFn

Ansi returns a function which colors a string using the ANSI 16 color pallette.

func (*Builder) Ansi256

func (builder *Builder) Ansi256(code uint8) ColorFn

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

func (builder *Builder) BgAnsi(code uint8) ColorFn

BgAnsi returns a function which colors the background of a string using the ANSI 16 color pallette.

func (*Builder) BgAnsi256

func (builder *Builder) BgAnsi256(code uint8) ColorFn

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

func (builder *Builder) BgBlack(str ...string) string

BgBlack returns a string where the background color is Black, in addition to other styles from this builder.

func (*Builder) BgBlue

func (builder *Builder) BgBlue(str ...string) string

BgBlue returns a string where the background color is Blue, in addition to other styles from this builder.

func (*Builder) BgBrightBlack

func (builder *Builder) BgBrightBlack(str ...string) string

BgBrightBlack returns a string where the background color is BrightBlack, in addition to other styles from this builder.

func (*Builder) BgBrightBlue

func (builder *Builder) BgBrightBlue(str ...string) string

BgBrightBlue returns a string where the background color is BrightBlue, in addition to other styles from this builder.

func (*Builder) BgBrightCyan

func (builder *Builder) BgBrightCyan(str ...string) string

BgBrightCyan returns a string where the background color is BrightCyan, in addition to other styles from this builder.

func (*Builder) BgBrightGreen

func (builder *Builder) BgBrightGreen(str ...string) string

BgBrightGreen returns a string where the background color is BrightGreen, in addition to other styles from this builder.

func (*Builder) BgBrightMagenta

func (builder *Builder) BgBrightMagenta(str ...string) string

BgBrightMagenta returns a string where the background color is BrightMagenta, in addition to other styles from this builder.

func (*Builder) BgBrightRed

func (builder *Builder) BgBrightRed(str ...string) string

BgBrightRed returns a string where the background color is BrightRed, in addition to other styles from this builder.

func (*Builder) BgBrightWhite

func (builder *Builder) BgBrightWhite(str ...string) string

BgBrightWhite returns a string where the background color is BrightWhite, in addition to other styles from this builder.

func (*Builder) BgBrightYellow

func (builder *Builder) BgBrightYellow(str ...string) string

BgBrightYellow returns a string where the background color is BrightYellow, in addition to other styles from this builder.

func (*Builder) BgCyan

func (builder *Builder) BgCyan(str ...string) string

BgCyan returns a string where the background color is Cyan, in addition to other styles from this builder.

func (*Builder) BgGray

func (builder *Builder) BgGray(str ...string) string

BgGray returns a string where the background color is Gray, in addition to other styles from this builder.

func (*Builder) BgGreen

func (builder *Builder) BgGreen(str ...string) string

BgGreen returns a string where the background color is Green, in addition to other styles from this builder.

func (*Builder) BgGrey

func (builder *Builder) BgGrey(str ...string) string

BgGrey returns a string where the background color is Grey, in addition to other styles from this builder.

func (*Builder) BgHex

func (builder *Builder) BgHex(hex string) ColorFn

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

func (builder *Builder) BgMagenta(str ...string) string

BgMagenta returns a string where the background color is Magenta, in addition to other styles from this builder.

func (*Builder) BgRGB

func (builder *Builder) BgRGB(r uint8, g uint8, b uint8) ColorFn

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

func (builder *Builder) BgRed(str ...string) string

BgRed returns a string where the background color is Red, in addition to other styles from this builder.

func (*Builder) BgWhite

func (builder *Builder) BgWhite(str ...string) string

BgWhite returns a string where the background color is White, in addition to other styles from this builder.

func (*Builder) BgYellow

func (builder *Builder) BgYellow(str ...string) string

BgYellow returns a string where the background color is Yellow, in addition to other styles from this builder.

func (*Builder) Black

func (builder *Builder) Black(str ...string) string

Black returns a string where the color is black, in addition to other styles from this builder.

func (*Builder) Blue

func (builder *Builder) Blue(str ...string) string

Blue returns a string where the color is blue, in addition to other styles from this builder.

func (*Builder) Bold

func (builder *Builder) Bold(str ...string) string

Bold returns a string with the bold modifier, in addition to other styles from this builder.

func (*Builder) BrightBlack

func (builder *Builder) BrightBlack(str ...string) string

BrightBlack returns a string where the color is brightBlack, in addition to other styles from this builder.

func (*Builder) BrightBlue

func (builder *Builder) BrightBlue(str ...string) string

BrightBlue returns a string where the color is brightBlue, in addition to other styles from this builder.

func (*Builder) BrightCyan

func (builder *Builder) BrightCyan(str ...string) string

BrightCyan returns a string where the color is brightCyan, in addition to other styles from this builder.

func (*Builder) BrightGreen

func (builder *Builder) BrightGreen(str ...string) string

BrightGreen returns a string where the color is brightGreen, in addition to other styles from this builder.

func (*Builder) BrightMagenta

func (builder *Builder) BrightMagenta(str ...string) string

BrightMagenta returns a string where the color is brightMagenta, in addition to other styles from this builder.

func (*Builder) BrightRed

func (builder *Builder) BrightRed(str ...string) string

BrightRed returns a string where the color is brightRed, in addition to other styles from this builder.

func (*Builder) BrightWhite

func (builder *Builder) BrightWhite(str ...string) string

BrightWhite returns a string where the color is brightWhite, in addition to other styles from this builder.

func (*Builder) BrightYellow

func (builder *Builder) BrightYellow(str ...string) string

BrightYellow returns a string where the color is brightYellow, in addition to other styles from this builder.

func (*Builder) Cyan

func (builder *Builder) Cyan(str ...string) string

Cyan returns a string where the color is cyan, in addition to other styles from this builder.

func (*Builder) Dim

func (builder *Builder) Dim(str ...string) string

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

func (builder *Builder) Gray(str ...string) string

Gray returns a string where the color is gray, in addition to other styles from this builder.

func (*Builder) Green

func (builder *Builder) Green(str ...string) string

Green returns a string where the color is green, in addition to other styles from this builder.

func (*Builder) Grey

func (builder *Builder) Grey(str ...string) string

Grey returns a string where the color is grey, in addition to other styles from this builder.

func (*Builder) Hex

func (builder *Builder) Hex(hex string) ColorFn

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

func (builder *Builder) Hidden(str ...string) string

Hidden returns a string with the hidden modifier, in addition to other styles from this builder.

func (*Builder) Inverse

func (builder *Builder) Inverse(str ...string) string

Inverse returns a string with the inverse modifier, in addition to other styles from this builder.

func (*Builder) Italic

func (builder *Builder) Italic(str ...string) string

Italic returns a string with the italic modifier, in addition to other styles from this builder.

func (*Builder) Magenta

func (builder *Builder) Magenta(str ...string) string

Magenta returns a string where the color is magenta, in addition to other styles from this builder.

func (*Builder) Overline

func (builder *Builder) Overline(str ...string) string

Overline returns a string with the overline modifier, in addition to other styles from this builder.

func (*Builder) Paint

func (builder *Builder) Paint(strs ...string) string

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

func (builder *Builder) RGB(r uint8, g uint8, b uint8) ColorFn

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

func (builder *Builder) Red(str ...string) string

Red returns a string where the color is red, in addition to other styles from this builder.

func (*Builder) Reset

func (builder *Builder) Reset(str ...string) string

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

func (builder *Builder) Sprintf(format string, a ...interface{}) string

Sprintf is a convenience function for coloring formatted strings.

gchalk.WithRed().Sprtinf("Hello %s", "World!")

func (*Builder) Strikethrough

func (builder *Builder) Strikethrough(str ...string) string

Strikethrough returns a string with the strikethrough modifier, in addition to other styles from this builder.

func (*Builder) Style

func (builder *Builder) Style(styles ...string) (ColorFn, error)

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

func (builder *Builder) StyleMust(styles ...string) ColorFn

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

func (builder *Builder) Underline(str ...string) string

Underline returns a string with the underline modifier, in addition to other styles from this builder.

func (*Builder) White

func (builder *Builder) White(str ...string) string

White returns a string where the color is white, in addition to other styles from this builder.

func (*Builder) WithAnsi

func (builder *Builder) WithAnsi(code uint8) *Builder

WithAnsi returns a Builder that generates strings with the specified color.

func (*Builder) WithAnsi256

func (builder *Builder) WithAnsi256(code uint8) *Builder

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

func (builder *Builder) WithBgAnsi(code uint8) *Builder

WithBgAnsi returns a Builder that generates strings with the specified background color.

func (*Builder) WithBgAnsi256

func (builder *Builder) WithBgAnsi256(code uint8) *Builder

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

func (builder *Builder) WithBgBlack() *Builder

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

func (builder *Builder) WithBgBlue() *Builder

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

func (builder *Builder) WithBgBrightBlack() *Builder

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

func (builder *Builder) WithBgBrightBlue() *Builder

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

func (builder *Builder) WithBgBrightCyan() *Builder

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

func (builder *Builder) WithBgBrightGreen() *Builder

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

func (builder *Builder) WithBgBrightMagenta() *Builder

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

func (builder *Builder) WithBgBrightRed() *Builder

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

func (builder *Builder) WithBgBrightWhite() *Builder

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

func (builder *Builder) WithBgBrightYellow() *Builder

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

func (builder *Builder) WithBgCyan() *Builder

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

func (builder *Builder) WithBgGray() *Builder

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

func (builder *Builder) WithBgGreen() *Builder

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

func (builder *Builder) WithBgGrey() *Builder

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

func (builder *Builder) WithBgHex(hex string) *Builder

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

func (builder *Builder) WithBgMagenta() *Builder

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

func (builder *Builder) WithBgRGB(r uint8, g uint8, b uint8) *Builder

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

func (builder *Builder) WithBgRed() *Builder

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

func (builder *Builder) WithBgWhite() *Builder

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

func (builder *Builder) WithBgYellow() *Builder

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

func (builder *Builder) WithBlack() *Builder

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

func (builder *Builder) WithBlue() *Builder

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

func (builder *Builder) WithBold() *Builder

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

func (builder *Builder) WithBrightBlack() *Builder

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

func (builder *Builder) WithBrightBlue() *Builder

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

func (builder *Builder) WithBrightCyan() *Builder

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

func (builder *Builder) WithBrightGreen() *Builder

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

func (builder *Builder) WithBrightMagenta() *Builder

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

func (builder *Builder) WithBrightRed() *Builder

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

func (builder *Builder) WithBrightWhite() *Builder

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

func (builder *Builder) WithBrightYellow() *Builder

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

func (builder *Builder) WithCyan() *Builder

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

func (builder *Builder) WithDim() *Builder

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

func (builder *Builder) WithGray() *Builder

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

func (builder *Builder) WithGreen() *Builder

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

func (builder *Builder) WithGrey() *Builder

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

func (builder *Builder) WithHex(hex string) *Builder

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

func (builder *Builder) WithHidden() *Builder

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

func (builder *Builder) WithInverse() *Builder

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

func (builder *Builder) WithItalic() *Builder

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

func (builder *Builder) WithMagenta() *Builder

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

func (builder *Builder) WithOverline() *Builder

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

func (builder *Builder) WithRGB(r uint8, g uint8, b uint8) *Builder

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

func (builder *Builder) WithRed() *Builder

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

func (builder *Builder) WithReset() *Builder

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

func (builder *Builder) WithStrikethrough() *Builder

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

func (builder *Builder) WithStyle(styles ...string) (*Builder, error)

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

func (builder *Builder) WithStyleMust(styles ...string) *Builder

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

func (builder *Builder) WithUnderline() *Builder

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

func (builder *Builder) WithWhite() *Builder

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

func (builder *Builder) WithYellow() *Builder

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.

func (*Builder) Yellow

func (builder *Builder) Yellow(str ...string) string

Yellow returns a string where the color is yellow, in addition to other styles from this builder.

type ColorFn added in v1.3.0

type ColorFn func(str ...string) string

ColorFn is a convenience type for a function that takes in a string and returns a colored string.

func Ansi

func Ansi(code uint8) ColorFn

Ansi returns a function which colors a string using the ANSI 16 color pallette.

func Ansi256

func Ansi256(code uint8) ColorFn

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

func BgAnsi(code uint8) ColorFn

BgAnsi returns a function which colors the background of a string using the ANSI 16 color pallette.

func BgAnsi256

func BgAnsi256(code uint8) ColorFn

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

func BgHex(hex string) ColorFn

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

func BgRGB(r uint8, g uint8, b uint8) ColorFn

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

func Hex(hex string) ColorFn

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

func RGB(r uint8, g uint8, b uint8) ColorFn

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

func Style(styles ...string) (ColorFn, error)

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 StyleMust

func StyleMust(styles ...string) ColorFn

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.

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
)

func GetLevel

func GetLevel() ColorLevel

GetLevel returns the currently configured color level.

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.

Jump to

Keyboard shortcuts

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