color

package
v0.0.0-...-b30915f Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2019 License: MIT Imports: 6 Imported by: 0

README

Color

Style terminal text.

Installation

go get github.com/srelab/common/color

Windows?

Try cmder or https://github.com/mattn/go-colorable

Usage

import github.com/srelab/common/color
Colored text
color.Println(color.Black("black"))
color.Println(color.Red("red"))
color.Println(color.Green("green"))
color.Println(color.Yellow("yellow"))
color.Println(color.Blue("blue"))
color.Println(color.Magenta("magenta"))
color.Println(color.Cyan("cyan"))
color.Println(color.White("white"))
color.Println(color.Grey("grey"))

Colored Text

Colored background
color.Println(color.BlackBg("black background", color.Wht))
color.Println(color.RedBg("red background"))
color.Println(color.GreenBg("green background"))
color.Println(color.YellowBg("yellow background"))
color.Println(color.BlueBg("blue background"))
color.Println(color.MagentaBg("magenta background"))
color.Println(color.CyanBg("cyan background"))
color.Println(color.WhiteBg("white background"))

Colored Background

Emphasis
color.Println(color.Bold("bold"))
color.Println(color.Dim("dim"))
color.Println(color.Italic("italic"))
color.Println(color.Underline("underline"))
color.Println(color.Inverse("inverse"))
color.Println(color.Hidden("hidden"))
color.Println(color.Strikeout("strikeout"))

Emphasis

Mix and match
color.Println(color.Green("bold green with white background", color.B, color.WhtBg))
color.Println(color.Red("underline red", color.U))
color.Println(color.Yellow("dim yellow", color.D))
color.Println(color.Cyan("inverse cyan", color.In))
color.Println(color.Blue("bold underline dim blue", color.B, color.U, color.D))

Mix and match

Enable/Disable the package
color.Disable()
color.Enable()
New instance
c := New()
c.Green("green")

Documentation

Index

Constants

View Source
const (
	// Blk Black text style
	Blk = "30"
	// Rd red text style
	Rd = "31"
	// Grn green text style
	Grn = "32"
	// Yel yellow text style
	Yel = "33"
	// Blu blue text style
	Blu = "34"
	// Mgn magenta text style
	Mgn = "35"
	// Cyn cyan text style
	Cyn = "36"
	// Wht white text style
	Wht = "37"
	// Gry grey text style
	Gry = "90"

	// BlkBg black background style
	BlkBg = "40"
	// RdBg red background style
	RdBg = "41"
	// GrnBg green background style
	GrnBg = "42"
	// YelBg yellow background style
	YelBg = "43"
	// BluBg blue background style
	BluBg = "44"
	// MgnBg magenta background style
	MgnBg = "45"
	// CynBg cyan background style
	CynBg = "46"
	// WhtBg white background style
	WhtBg = "47"

	// R reset emphasis style
	R = "0"
	// B bold emphasis style
	B = "1"
	// D dim emphasis style
	D = "2"
	// I italic emphasis style
	I = "3"
	// U underline emphasis style
	U = "4"
	// In inverse emphasis style
	In = "7"
	// H hidden emphasis style
	H = "8"
	// S strikeout emphasis style
	S = "9"
)

Color styles

Variables

This section is empty.

Functions

func Black

func Black(msg interface{}, styles ...string) string

func BlackBg

func BlackBg(msg interface{}, styles ...string) string

func Blue

func Blue(msg interface{}, styles ...string) string

func BlueBg

func BlueBg(msg interface{}, styles ...string) string

func Bold

func Bold(msg interface{}, styles ...string) string

func Cyan

func Cyan(msg interface{}, styles ...string) string

func CyanBg

func CyanBg(msg interface{}, styles ...string) string

func Dim

func Dim(msg interface{}, styles ...string) string

func Disable

func Disable()

func Enable

func Enable()

func Green

func Green(msg interface{}, styles ...string) string

func GreenBg

func GreenBg(msg interface{}, styles ...string) string

func Grey

func Grey(msg interface{}, styles ...string) string

func Hidden

func Hidden(msg interface{}, styles ...string) string

func Inverse

func Inverse(msg interface{}, styles ...string) string

func Italic

func Italic(msg interface{}, styles ...string) string

func Magenta

func Magenta(msg interface{}, styles ...string) string

func MagentaBg

func MagentaBg(msg interface{}, styles ...string) string

func Output

func Output() io.Writer

Output returns the output.

func Print

func Print(args ...interface{})

Print is analogous to `fmt.Print` with termial detection.

func Printf

func Printf(format string, args ...interface{})

Printf is analogous to `fmt.Printf` with termial detection.

func Println

func Println(args ...interface{})

Println is analogous to `fmt.Println` with termial detection.

func Red

func Red(msg interface{}, styles ...string) string

func RedBg

func RedBg(msg interface{}, styles ...string) string

func Reset

func Reset(msg interface{}, styles ...string) string

func SetOutput

func SetOutput(w io.Writer)

SetOutput sets the output.

func Strikeout

func Strikeout(msg interface{}, styles ...string) string

func Underline

func Underline(msg interface{}, styles ...string) string

func White

func White(msg interface{}, styles ...string) string

func WhiteBg

func WhiteBg(msg interface{}, styles ...string) string

func Yellow

func Yellow(msg interface{}, styles ...string) string

func YellowBg

func YellowBg(msg interface{}, styles ...string) string

Types

type Color

type Color struct {
	// contains filtered or unexported fields
}

func New

func New() (c *Color)

New creates a Color instance.

func (*Color) Black

func (c *Color) Black(msg interface{}, styles ...string) string

func (*Color) BlackBg

func (c *Color) BlackBg(msg interface{}, styles ...string) string

func (*Color) Blue

func (c *Color) Blue(msg interface{}, styles ...string) string

func (*Color) BlueBg

func (c *Color) BlueBg(msg interface{}, styles ...string) string

func (*Color) Bold

func (c *Color) Bold(msg interface{}, styles ...string) string

func (*Color) Cyan

func (c *Color) Cyan(msg interface{}, styles ...string) string

func (*Color) CyanBg

func (c *Color) CyanBg(msg interface{}, styles ...string) string

func (*Color) Dim

func (c *Color) Dim(msg interface{}, styles ...string) string

func (*Color) Disable

func (c *Color) Disable()

Disable disables the colors and styles.

func (*Color) Enable

func (c *Color) Enable()

Enable enables the colors and styles.

func (*Color) Green

func (c *Color) Green(msg interface{}, styles ...string) string

func (*Color) GreenBg

func (c *Color) GreenBg(msg interface{}, styles ...string) string

func (*Color) Grey

func (c *Color) Grey(msg interface{}, styles ...string) string

func (*Color) Hidden

func (c *Color) Hidden(msg interface{}, styles ...string) string

func (*Color) Inverse

func (c *Color) Inverse(msg interface{}, styles ...string) string

func (*Color) Italic

func (c *Color) Italic(msg interface{}, styles ...string) string

func (*Color) Magenta

func (c *Color) Magenta(msg interface{}, styles ...string) string

func (*Color) MagentaBg

func (c *Color) MagentaBg(msg interface{}, styles ...string) string

func (*Color) Output

func (c *Color) Output() io.Writer

Output returns the output.

func (*Color) Print

func (c *Color) Print(args ...interface{})

Print is analogous to `fmt.Print` with termial detection.

func (*Color) Printf

func (c *Color) Printf(format string, args ...interface{})

Printf is analogous to `fmt.Printf` with termial detection.

func (*Color) Println

func (c *Color) Println(args ...interface{})

Println is analogous to `fmt.Println` with termial detection.

func (*Color) Red

func (c *Color) Red(msg interface{}, styles ...string) string

func (*Color) RedBg

func (c *Color) RedBg(msg interface{}, styles ...string) string

func (*Color) Reset

func (c *Color) Reset(msg interface{}, styles ...string) string

func (*Color) SetOutput

func (c *Color) SetOutput(w io.Writer)

SetOutput sets the output.

func (*Color) Strikeout

func (c *Color) Strikeout(msg interface{}, styles ...string) string

func (*Color) Underline

func (c *Color) Underline(msg interface{}, styles ...string) string

func (*Color) White

func (c *Color) White(msg interface{}, styles ...string) string

func (*Color) WhiteBg

func (c *Color) WhiteBg(msg interface{}, styles ...string) string

func (*Color) Yellow

func (c *Color) Yellow(msg interface{}, styles ...string) string

func (*Color) YellowBg

func (c *Color) YellowBg(msg interface{}, styles ...string) string

Jump to

Keyboard shortcuts

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