chalk

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2022 License: MIT Imports: 2 Imported by: 7

README

Chalk

Chalk is a Go Package which can be used for making terminal output more vibrant with text colors, text styles and background colors.

Documentation

Check out godoc for some example usage: http://godoc.org/github.com/golang-demos/chalk

Example Code

ExampleCode

Example Output

SampleOutput

Colors

Colors TextColor Background-Color
Black chalk.Black("Black-Text") chalk.BgBlack("Black-Background")
BlackLight chalk.BlackLight("BlackLight-Text") chalk.BgBlackLight("BlackLight-Background")
Red chalk.Red("Red-Text") chalk.BgRed("Red-Background")
RedLight chalk.RedLight("RedLight-Text") chalk.BgRedLight("RedLight-Background")
Green chalk.Green("Green-Text") chalk.BgGreen("Green-Background")
GreenLight chalk.GreenLight("GreenLight-Text") chalk.BgGreenLight("GreenLight-Background")
Yellow chalk.Yellow("Yellow-Text") chalk.BgYellow("Yellow-Background")
YellowLight chalk.YellowLight("YellowLight-Text") chalk.BgYellowLight("YellowLight-Background")
Blue chalk.Blue("Blue-Text") chalk.BgBlue("Blue-Background")
BlueLight chalk.BlueLight("BlueLight-Text") chalk.BgBlueLight("BlueLight-Background")
Magenta chalk.Magenta("Magenta-Text") chalk.BgMagenta("Magenta-Background")
MagentaLight chalk.MagentaLight("MagentaLight-Text") chalk.BgMagentaLight("MagentaLight-Background")
Cyan chalk.Cyan("Cyan-Text") chalk.BgCyan("Cyan-Background")
CyanLight chalk.CyanLight("CyanLight-Text") chalk.BgCyanLight("CyanLight-Background")
White chalk.White("White-Text") chalk.BgWhite("White-Background")
WhiteLight chalk.WhiteLight("WhiteLight-Text") chalk.BgWhiteLight("WhiteLight-Background")

Basic Formatting

Formatting Use
Bold chalk.Bold("Bold-Text")
Dim chalk.Dim("Dim-Text")
Italic chalk.Italic("Italic-Text")
Underline chalk.Underline("Underline-Text")
Inverse chalk.Inverse("Inverse-Text")
Hidden chalk.Hidden("Hidden-Text")
Strikethrough chalk.Strikethrough("Strikethrough-Text")

Sample Code

package main

import (
	"fmt"

	"github.com/golang-demos/chalk"
)

func main() {
	// Colors
	fmt.Println(chalk.BlackLight("BlackLight-Text"))
	fmt.Println(chalk.Blue("Blue-Text"))

	// Basic Formatting
	fmt.Println(chalk.Underline("Underline-Text"))
	fmt.Println(chalk.Bold("Bold-Text"))

	// Background Coloring
	fmt.Println(chalk.BgYellow("Yellow-Background-Text"))

	// Mixed
	fmt.Println(chalk.Red().Italic("Red Italic Text"))
	fmt.Println(chalk.Green().Strikethrough("Green Strikethrough text"))
	fmt.Println(chalk.Cyan().Underline().BgBlackLight("Cyan Underline text on BlackLight Background"))
	fmt.Println(chalk.Yellow().BgRed().Inverse("Yellow text on Red background with inverted colors"))

	// For Existing Code
	fmt.Print(chalk.Green())
	fmt.Println("Data Sent Successfully")
	fmt.Print(chalk.Reset())

	// Reusable Configurations
	SuccessMessage := chalk.Green().Bold("SUCCESS : ")
	fmt.Println(SuccessMessage.Apply("Completed successfully"))
	fmt.Println(SuccessMessage.Apply("Process Complete"))
}

Source

Author

Vinay Jeurkar

   

Documentation

Overview

Chalk is a Go Package which can be used for making terminal output more vibrant with text colors, text styles and background colors. The styling factors are: - Text Color - Text Style - Background Color

Text Color

There are sixteen Colors. You can use them as follow :

fmt.Println(chalk.Black("Black-Text"))
fmt.Println(chalk.BlackLight("BlackLight-Text"))
fmt.Println(chalk.Red("Red-Text"))
fmt.Println(chalk.RedLight("RedLight-Text"))
fmt.Println(chalk.Green("Green-Text"))
fmt.Println(chalk.GreenLight("GreenLight-Text"))
fmt.Println(chalk.Yellow("Yellow-Text"))
fmt.Println(chalk.YellowLight("YellowLight-Text"))
fmt.Println(chalk.Blue("Blue-Text"))
fmt.Println(chalk.BlueLight("BlueLight-Text"))
fmt.Println(chalk.Magenta("Magenta-Text"))
fmt.Println(chalk.MagentaLight("MagentaLight-Text"))
fmt.Println(chalk.Cyan("Cyan-Text"))
fmt.Println(chalk.CyanLight("CyanLight-Text"))
fmt.Println(chalk.White("White-Text"))
fmt.Println(chalk.WhiteLight("WhiteLight-Text"))

Text Style

There are seven text styles. You can use them as follow:

fmt.Println(chalk.Bold("Bold-Text"))
fmt.Println(chalk.Dim("Dim-Text"))
fmt.Println(chalk.Italic("Italic-Text"))
fmt.Println(chalk.Underline("Underline-Text"))
fmt.Println(chalk.Inverse("Inverse-Text"))
fmt.Println(chalk.Hidden("Hidden-Text"))
fmt.Println(chalk.Strikethrough("Strikethrough-Text"))

Background Color

There are sixteen background colors. You can use them as follow:

fmt.Println(chalk.WhiteLight().BgBlack("WhiteLight-Text-on-BgBlack"))
fmt.Println(chalk.WhiteLight().BgBlackLight("WhiteLight-Text-on-BgBlackLight"))
fmt.Println(chalk.Black().BgRed("Black-Text-on-BgRed"))
fmt.Println(chalk.Black().BgRedLight("Black-Text-on-BgRedLight"))
fmt.Println(chalk.Black().BgGreen("Black-Text-on-BgGreen"))
fmt.Println(chalk.Black().BgGreenLight("Black-Text-on-BgGreenLight"))
fmt.Println(chalk.Black().BgYellow("Black-Text-on-BgYellow"))
fmt.Println(chalk.Black().BgYellowLight("Black-Text-on-BgYellowLight"))
fmt.Println(chalk.Black().BgBlue("Black-Text-on-BgBlue"))
fmt.Println(chalk.Black().BgBlueLight("Black-Text-on-BgBlueLight"))
fmt.Println(chalk.Black().BgMagenta("Black-Text-on-BgMagenta"))
fmt.Println(chalk.Black().BgMagentaLight("Black-Text-on-BgMagentaLight"))
fmt.Println(chalk.Black().BgCyan("Black-Text-on-BgCyan"))
fmt.Println(chalk.Black().BgCyanLight("Black-Text-on-BgCyanLight"))
fmt.Println(chalk.Black().BgWhite("Black-Text-on-BgWhite"))
fmt.Println(chalk.Black().BgWhiteLight("Black-Text-on-BgWhiteLight"))

You can use above functions in combinations. Following are some examples to refer:

fmt.Println(chalk.Red().Italic("Red-Italic-Text"))
fmt.Println(chalk.Green().Strikethrough("Green-Strikethrough-Text"))
fmt.Println(chalk.Cyan().Underline().BgBlackLight("Cyan-underline-text-on-BgBlackLight"))
fmt.Println(chalk.Yellow().BgRed().Inverse("Yellow-text-on-red-inverted"))

You can save formatting configuration in a variable and reuse them multiple times. examples to refer:

SuccessMessage := chalk.Green().Bold("SUCCESS : ")
WarningMessage := chalk.YellowLight().Bold("WARNING : ")
ErrorMessage := chalk.RedLight().Bold("ERROR   : ")
fmt.Println(SuccessMessage.Apply("Completed successfully"))
fmt.Println(SuccessMessage.Apply("Process Complete"))
fmt.Println(WarningMessage.Apply("Call Deprecated"))
fmt.Println(ErrorMessage.Apply("Fatal error ocurred"))

Index

Constants

This section is empty.

Variables

View Source
var (
	// Text Colors
	Black   = func(msgs ...interface{}) *Color { return newColor().Black(msgs...) }
	Red     = func(msgs ...interface{}) *Color { return newColor().Red(msgs...) }
	Green   = func(msgs ...interface{}) *Color { return newColor().Green(msgs...) }
	Yellow  = func(msgs ...interface{}) *Color { return newColor().Yellow(msgs...) }
	Blue    = func(msgs ...interface{}) *Color { return newColor().Blue(msgs...) }
	Magenta = func(msgs ...interface{}) *Color { return newColor().Magenta(msgs...) }
	Cyan    = func(msgs ...interface{}) *Color { return newColor().Cyan(msgs...) }
	White   = func(msgs ...interface{}) *Color { return newColor().White(msgs...) }

	// Text Light Colors
	BlackLight   = func(msgs ...interface{}) *Color { return newColor().BlackLight(msgs...) }
	RedLight     = func(msgs ...interface{}) *Color { return newColor().RedLight(msgs...) }
	GreenLight   = func(msgs ...interface{}) *Color { return newColor().GreenLight(msgs...) }
	YellowLight  = func(msgs ...interface{}) *Color { return newColor().YellowLight(msgs...) }
	BlueLight    = func(msgs ...interface{}) *Color { return newColor().BlueLight(msgs...) }
	MagentaLight = func(msgs ...interface{}) *Color { return newColor().MagentaLight(msgs...) }
	CyanLight    = func(msgs ...interface{}) *Color { return newColor().CyanLight(msgs...) }
	WhiteLight   = func(msgs ...interface{}) *Color { return newColor().WhiteLight(msgs...) }

	// Text Styles
	Bold          = func(msgs ...interface{}) *Color { return newColor().Bold(msgs...) }
	Dim           = func(msgs ...interface{}) *Color { return newColor().Dim(msgs...) }
	Italic        = func(msgs ...interface{}) *Color { return newColor().Italic(msgs...) }
	Underline     = func(msgs ...interface{}) *Color { return newColor().Underline(msgs...) }
	Inverse       = func(msgs ...interface{}) *Color { return newColor().Inverse(msgs...) }
	Hidden        = func(msgs ...interface{}) *Color { return newColor().Hidden(msgs...) }
	Strikethrough = func(msgs ...interface{}) *Color { return newColor().Strikethrough(msgs...) }

	// Background Colors
	BgBlack   = func(msgs ...interface{}) *Color { return newColor().BgBlack(msgs...) }
	BgRed     = func(msgs ...interface{}) *Color { return newColor().BgRed(msgs...) }
	BgGreen   = func(msgs ...interface{}) *Color { return newColor().BgGreen(msgs...) }
	BgYellow  = func(msgs ...interface{}) *Color { return newColor().BgYellow(msgs...) }
	BgBlue    = func(msgs ...interface{}) *Color { return newColor().BgBlue(msgs...) }
	BgMagenta = func(msgs ...interface{}) *Color { return newColor().BgMagenta(msgs...) }
	BgCyan    = func(msgs ...interface{}) *Color { return newColor().BgCyan(msgs...) }
	BgWhite   = func(msgs ...interface{}) *Color { return newColor().BgWhite(msgs...) }

	BgBlackLight   = func(msgs ...interface{}) *Color { return newColor().BgBlackLight(msgs...) }
	BgRedLight     = func(msgs ...interface{}) *Color { return newColor().BgRedLight(msgs...) }
	BgGreenLight   = func(msgs ...interface{}) *Color { return newColor().BgGreenLight(msgs...) }
	BgYellowLight  = func(msgs ...interface{}) *Color { return newColor().BgYellowLight(msgs...) }
	BgBlueLight    = func(msgs ...interface{}) *Color { return newColor().BgBlueLight(msgs...) }
	BgMagentaLight = func(msgs ...interface{}) *Color { return newColor().BgMagentaLight(msgs...) }
	BgCyanLight    = func(msgs ...interface{}) *Color { return newColor().BgCyanLight(msgs...) }
	BgWhiteLight   = func(msgs ...interface{}) *Color { return newColor().BgWhiteLight(msgs...) }
)

Functions

func Reset

func Reset() string

For all reset. BackgroundColor and TextColor

Types

type Color

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

func (Color) Apply added in v1.1.3

func (c Color) Apply(msgs ...interface{}) Color

func (*Color) BgBlack

func (c *Color) BgBlack(msgs ...interface{}) *Color

Background Colors

func (*Color) BgBlackLight

func (c *Color) BgBlackLight(msgs ...interface{}) *Color

func (*Color) BgBlue

func (c *Color) BgBlue(msgs ...interface{}) *Color

func (*Color) BgBlueLight

func (c *Color) BgBlueLight(msgs ...interface{}) *Color

func (*Color) BgCyan

func (c *Color) BgCyan(msgs ...interface{}) *Color

func (*Color) BgCyanLight

func (c *Color) BgCyanLight(msgs ...interface{}) *Color

func (*Color) BgGreen

func (c *Color) BgGreen(msgs ...interface{}) *Color

func (*Color) BgGreenLight

func (c *Color) BgGreenLight(msgs ...interface{}) *Color

func (*Color) BgMagenta

func (c *Color) BgMagenta(msgs ...interface{}) *Color

func (*Color) BgMagentaLight

func (c *Color) BgMagentaLight(msgs ...interface{}) *Color

func (*Color) BgRed

func (c *Color) BgRed(msgs ...interface{}) *Color

func (*Color) BgRedLight

func (c *Color) BgRedLight(msgs ...interface{}) *Color

func (*Color) BgWhite

func (c *Color) BgWhite(msgs ...interface{}) *Color

func (*Color) BgWhiteLight

func (c *Color) BgWhiteLight(msgs ...interface{}) *Color

func (*Color) BgYellow

func (c *Color) BgYellow(msgs ...interface{}) *Color

func (*Color) BgYellowLight

func (c *Color) BgYellowLight(msgs ...interface{}) *Color

func (*Color) Black

func (c *Color) Black(msgs ...interface{}) *Color

Colors

func (*Color) BlackLight

func (c *Color) BlackLight(msgs ...interface{}) *Color

func (*Color) Blue

func (c *Color) Blue(msgs ...interface{}) *Color

func (*Color) BlueLight

func (c *Color) BlueLight(msgs ...interface{}) *Color

func (*Color) Bold

func (c *Color) Bold(msgs ...interface{}) *Color

Text Styles

func (*Color) Cyan

func (c *Color) Cyan(msgs ...interface{}) *Color

func (*Color) CyanLight

func (c *Color) CyanLight(msgs ...interface{}) *Color

func (*Color) Dim

func (c *Color) Dim(msgs ...interface{}) *Color

func (*Color) Green

func (c *Color) Green(msgs ...interface{}) *Color

func (*Color) GreenLight

func (c *Color) GreenLight(msgs ...interface{}) *Color

func (*Color) Hidden

func (c *Color) Hidden(msgs ...interface{}) *Color

func (*Color) Inverse

func (c *Color) Inverse(msgs ...interface{}) *Color

func (*Color) Italic

func (c *Color) Italic(msgs ...interface{}) *Color

func (*Color) Magenta

func (c *Color) Magenta(msgs ...interface{}) *Color

func (*Color) MagentaLight

func (c *Color) MagentaLight(msgs ...interface{}) *Color

func (*Color) Red

func (c *Color) Red(msgs ...interface{}) *Color

func (*Color) RedLight

func (c *Color) RedLight(msgs ...interface{}) *Color

func (*Color) SetText added in v1.1.2

func (c *Color) SetText(msgs []interface{}) *Color

func (*Color) Strikethrough

func (c *Color) Strikethrough(msgs ...interface{}) *Color

func (Color) String

func (c Color) String() string

func (*Color) Underline

func (c *Color) Underline(msgs ...interface{}) *Color

func (*Color) White

func (c *Color) White(msgs ...interface{}) *Color

func (*Color) WhiteLight

func (c *Color) WhiteLight(msgs ...interface{}) *Color

func (*Color) Yellow

func (c *Color) Yellow(msgs ...interface{}) *Color

func (*Color) YellowLight

func (c *Color) YellowLight(msgs ...interface{}) *Color

type PrintableText added in v1.1.2

type PrintableText interface {
	String() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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