- Go 100%
| background24.go | ||
| background24_test.go | ||
| foreground24.go | ||
| foreground24_test.go | ||
| go.mod | ||
| LICENSE | ||
| README.md | ||
| reset.go | ||
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
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