Skip to content

UnnamedXAer/colrz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

colrz

GoDoc Go Report Card

It's a set of funcs and constants to provide basic colors to your terminal app.

How to use

Get it

go get github.com/unnamedxaer/colrz

Use it

package main

import (
	"fmt"

	c "github.com/unnamedxaer/colrz"
)

func main() {
	// with method
	fmt.Print(c.Yellow("\nThe tree is yellow."))

	// with const
	fmt.Printf("\n%sThe tree is red.%s", c.FgRed, c.FgReset)

	// background color
	fmt.Printf("\n%s", c.BlueBg(c.Yellow("The tree is green with blue leafs.")))

	fmt.Printf("\n%s", c.WhiteBg(c.Green("The tree is green and ")+c.Yellow("yellow with white leafs.")))

	fmt.Printf("\n%s", c.Yellow(c.MagentaBg("The tree is yellow ")+c.CyanBg(" with colorful leafs.")))

	fmt.Printf("\n%s%sThe tree is %s yellow with %scolorful leafs.%s%s",
		c.BgMagenta, c.FgYellow, c.BgCyan, c.FgBlack, c.BgReset, c.FgReset)
}

output from above code snippet

  • Use colored text
fmt.Print(c.Red("The tree is red."))

red text

  • Use colored text on colored background
fmt.Printf("\n%s", c.BlueBg(c.Red("The tree is red with blue leafs.")))

red text on blue background color

Persistent coloring

If you set color via constant and do not reset it, then the color will persist for the next prints.

	fmt.Printf("\n%sThe tree is red.", c.FgRed)
	// ... some code
	fmt.Printf("\ndone at %v", time.Now().Local())
	// ... some code maybe more prints
	// restore color to normal
	fmt.Print(c.FgReset)
	fmt.Print("\nThe winter is coming, the leaves have fallen.")

persistent text color

All colors

all colors example

Colors in different terminals

Colors may and will vary slightly depending on the terminals.

cmder colors example

Warning

Not all terminals support this features eg. windows cmd / ps < 7.0

example of terminal not supporting colors

License

MIT. See the LICENSE file for more details.