Golang: Color Outputs colored text on the terminal

Golang color

Color lets you use colorized outputs in terms of ANSI Escape Codes in Go (Golang). It has support for Windows too! The API can be used in several ways, pick one that suits you.

The installation

go get github.com/fatih/color
// main.go
package main
import (
func main() {
// Print the text in blue
color.Blue("hello: %s", "Tom")
// Use it after instantiation
colorPrint := color.New()
Colorprint. Add(color.fgred) // Red text
ColorPrint. Add (color. Italic) / / tilt
Colorprint.add (color.bggreen) // Green background
colorPrint.Println("Hello World")

Note: Running directly has no effect. You need to run the command line on the terminal to see the effect

$ go run main.go

Leave a Reply

Your email address will not be published. Required fields are marked *