color

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 6 Imported by: 1,072

README

Color

Style terminal text.

Installation

go get github.com/labstack/gommon/color

Windows?

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

Usage

import github.com/labstack/gommon/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 added in v0.1.0

func Disable()

func Enable added in v0.1.0

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 added in v0.1.0

func Output() io.Writer

Output returns the output.

func Print added in v0.1.0

func Print(args ...interface{})

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

func Printf added in v0.1.0

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

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

func Println added in v0.1.0

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 added in v0.1.0

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 added in v0.1.0

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

func New added in v0.1.0

func New() (c *Color)

New creates a Color instance.

func (*Color) Black added in v0.1.0

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

func (*Color) BlackBg added in v0.1.0

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

func (*Color) Blue added in v0.1.0

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

func (*Color) BlueBg added in v0.1.0

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

func (*Color) Bold added in v0.1.0

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

func (*Color) Cyan added in v0.1.0

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

func (*Color) CyanBg added in v0.1.0

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

func (*Color) Dim added in v0.1.0

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

func (*Color) Disable added in v0.1.0

func (c *Color) Disable()

Disable disables the colors and styles.

func (*Color) Enable added in v0.1.0

func (c *Color) Enable()

Enable enables the colors and styles.

func (*Color) Green added in v0.1.0

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

func (*Color) GreenBg added in v0.1.0

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

func (*Color) Grey added in v0.1.0

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

func (*Color) Hidden added in v0.1.0

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

func (*Color) Inverse added in v0.1.0

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

func (*Color) Italic added in v0.1.0

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

func (*Color) Magenta added in v0.1.0

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

func (*Color) MagentaBg added in v0.1.0

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

func (*Color) Output added in v0.1.0

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

Output returns the output.

func (*Color) Print added in v0.1.0

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

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

func (*Color) Printf added in v0.1.0

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

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

func (*Color) Println added in v0.1.0

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

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

func (*Color) Red added in v0.1.0

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

func (*Color) RedBg added in v0.1.0

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

func (*Color) Reset added in v0.1.0

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

func (*Color) SetOutput added in v0.1.0

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

SetOutput sets the output.

func (*Color) Strikeout added in v0.1.0

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

func (*Color) Underline added in v0.1.0

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

func (*Color) White added in v0.1.0

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

func (*Color) WhiteBg added in v0.1.0

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

func (*Color) Yellow added in v0.1.0

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

func (*Color) YellowBg added in v0.1.0

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