colrz

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2022 License: MIT Imports: 1 Imported by: 0

README

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.

Documentation

Index

Constants

View Source
const (
	FgBlack   = "\033[30m"
	FgRed     = "\033[31m"
	FgGreen   = "\033[32m"
	FgYellow  = "\033[33m"
	FgBlue    = "\033[34m"
	FgMagenta = "\033[35m"
	FgCyan    = "\033[36m"
	FgWhite   = "\033[37m"

	FgReset = "\033[39m"
)
View Source
const (
	BgBlack   = "\033[40m"
	BgRed     = "\033[41m"
	BgGreen   = "\033[42m"
	BgYellow  = "\033[43m"
	BgBlue    = "\033[44m"
	BgMagenta = "\033[45m"
	BgCyan    = "\033[46m"
	BgWhite   = "\033[47m"

	BgReset = "\033[49m"
)

Variables

This section is empty.

Functions

func Black

func Black(s string) string

func BlackBg

func BlackBg(s string) string

func Blue

func Blue(s string) string

func BlueBg

func BlueBg(s string) string

func Cyan

func Cyan(s string) string

func CyanBg

func CyanBg(s string) string

func Green

func Green(s string) string

func GreenBg

func GreenBg(s string) string

func Magenta

func Magenta(s string) string

func MagentaBg

func MagentaBg(s string) string

func Red

func Red(s string) string

func RedBg

func RedBg(s string) string

func White

func White(s string) string

func WhiteBg

func WhiteBg(s string) string

func Yellow

func Yellow(s string) string

func YellowBg

func YellowBg(s string) string

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL