Skip to content
Docs
Modules
color

color

The color module provides functions to colorize text in the terminal.

The core functionality is provided by github.com/fatih/color (opens in a new tab).

Configuring colors and other text attributes is done using the various constants described below. Multiple constants can be passed to functions in this module to combine attributes.

Module

Function signature
color(options ...int) color.color

The color module object itself is callable, which is a shorthand for color.color().

Example
>>> color(color.fg_green).printf("hello!\n")
// colorized output

Functions

color

Function signature
color(options ...int) color.color

Creates a new color object with the specified options.

Example
>>> c := color.color(color.fg_red, color.bold)

set

Function signature
set(options ...int)

Sets the terminal color to the specified options.

Example
>>> color.set(color.fg_green, color.bold)

unset

Function signature
unset()

Resets the terminal color to the default.

Example
>>> color.unset()

Types

color

Defines a custom color object.

Methods

sprintf
Method signature
sprintf(format string, a ...object) string

Formats the string with the color object.

Example
>>> c := color.color(color.fg_red, color.bold)
>>> c.sprintf("Hello, %s!", "world")
"\x1b[31;1mHello, world!\x1b[0;22m"
>>> print(c.sprintf("Hello, %s!", "world"))
// colorized output
fprintf
Method signature
fprintf(w io.writer, format string, a ...object)

Writes the colorized, formatted string to the given writer.

Example
>>> b := buffer()
>>> c.fprintf(b, "Hello, %s!\n", "world")
>>> b
buffer("\x1b[31;1mHello, world!\n\x1b[0m")
printf
Method signature
printf(format string, a ...object)

Writes the colorized, formatted string to the standard output. Note you may need to include a trailing newline to flush the output.

Example
>>> c.printf("Hello, %s!\n", "world")
// colorized output

Constants

NameDescription
resetReset all attributes
boldBold text
dimDim text
italicItalic text
underlineUnderlined text
blinkslowBlinking text (slow)
blinkrapidBlinking text (rapid)
reversevideoReverse video
concealedConcealed text
crossedoutCrossed-out text
bg_blackBlack background color
bg_blueBlue background color
bg_cyanCyan background color
bg_greenGreen background color
bg_hiblackHigh-intensity black background color
bg_hiblueHigh-intensity blue background color
bg_hicyanHigh-intensity cyan background color
bg_higreenHigh-intensity green background color
bg_himagentaHigh-intensity magenta background color
bg_hiredHigh-intensity red background color
bg_hiwhiteHigh-intensity white background color
bg_hiyellowHigh-intensity yellow background color
bg_magentaMagenta background color
bg_redRed background color
bg_whiteWhite background color
bg_yellowYellow background color
fg_blackBlack foreground color
fg_blueBlue foreground color
fg_cyanCyan foreground color
fg_greenGreen foreground color
fg_hiblackHigh-intensity black foreground color
fg_hiblueHigh-intensity blue foreground color
fg_hicyanHigh-intensity cyan foreground color
fg_higreenHigh-intensity green foreground color
fg_himagentaHigh-intensity magenta foreground color
fg_hiredHigh-intensity red foreground color
fg_hiwhiteHigh-intensity white foreground color
fg_hiyellowHigh-intensity yellow foreground color
fg_magentaMagenta foreground color
fg_redRed foreground color
fg_whiteWhite foreground color
fg_yellowYellow foreground color