Package ansicolor provides tools for generating ANSI escape codes for setting the foreground and background colors, for the Go programming language.
Find a file
2025-12-10 05:46:48 -08:00
background24.go docs 2025-12-10 05:13:14 -08:00
background24_test.go ansicolor.BackGround24() 2025-12-10 05:08:56 -08:00
foreground24.go docs 2025-12-10 05:13:14 -08:00
foreground24_test.go ansicolor.ForeGround24() 2025-12-10 05:09:19 -08:00
go.mod go.* 2025-12-10 05:07:35 -08:00
LICENSE initial commits 2025-12-10 05:04:28 -08:00
README.md docs 2025-12-10 05:46:48 -08:00
reset.go docs 2025-12-10 05:16:35 -08:00

go-ansicolor

Package ansicolor provides tools for generating ANSI escape codes for setting the foreground and background colors, for the Go programming language.

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-ansicolor

GoDoc

Examples

Here is an example that makes the text of one word to a red (#dc322f / rgb(220,50,47)) and another word to a blue (#268bd2 / rgb(38,139,210)).

import "github.com/reiver/go-ansicolor"

// ...

codeRed := ansicolor.ForeGround24(220, 50, 47)
codeBlue := ansicolor.ForeGround24(38, 139, 210)

fmt.Printf("This is %sRED%s. This is %sBLUE%s.\n", codeRed, ansicolor.Reset, codeBlue, ansicolor.Reset)

We are using fmt.Printf() to send these (24-bit color) ANSI control codes (and the text) to the terminal (or terminal-emulator). The terminal (and terminal-emulator) are what respond to these (24-bit color) ANSI control codes.

Here is another example that sets the background color to #002b36 (rgb(0,43,54)) and the foreground color to #d33682 (rgb(211,54,130)):

import "github.com/reiver/go-ansicolor"

// ...

bgColor := ansicolor.BackgroundGround24(0, 43, 54)
fgColor := ansicolor.ForeGround24(211, 54, 130)

fmt.Printf("Hello %s%sworld%s!", bgColor, fgColor, ansicolor.Reset)

Import

To import package ansicolor use import code like the following:

import "github.com/reiver/go-ansicolor"

Installation

To install package ansicolor do the following:

GOPROXY=direct go get github.com/reiver/go-ansicolor

Author

Package ansicolor was written by Charles Iliya Krempeaux