Skip to content

ttkzw/go-color

Repository files navigation

go-color

This is a Go library for colorizing strings.

Usage

To give a color name, write as follows:

package main

import (
	"fmt"
	"log"

	"github.com/ttkzw/go-color"
)

func main() {
	c, err := color.NewColor("Green")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(c.Colorize("OK"))
}

To use built-in constants, write as follows:

package main

import (
	"fmt"

	"github.com/ttkzw/go-color"
)

func main() {
	fmt.Println(color.Green.Colorize("OK"))
}

To use a background color, write as follows:

package main

import (
	"fmt"

	"github.com/ttkzw/go-color"
)

func main() {
	fmt.Println(color.Colorize("OK", color.White, color.GreenBackground))
}

If you want to support Windows, use go-colorable.

package main

import (
	"fmt"

	"github.com/mattn/go-colorable"
	"github.com/ttkzw/go-color"
)

func main() {
	var output = colorable.NewColorableStdout()

	fmt.Fprintln(output, color.Green.Colorize("OK"))
}

Supported colors

Installation

$ go get github.com/ttkzw/go-color

License

BSD 3-Clause License

Auther

Takashi Takizawa

About

This is a Go library for colorizing strings.

Resources

License

Stars

Watchers

Forks

Packages

No packages published