text

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2019 License: GPL-3.0 Imports: 1 Imported by: 0

README

text

pipeline status coverage report Contributor Covenant

Implementation of colored text for the command line.

Install

go get -u lab.madbox.synology.me/gophers/text

Constants

These constants are taken from the ECMA-48 Standard and can be used in the Raw function.

Rendition modes
  • RndDFL = default rendition "0"
  • RndBLD = bold or increased intensity "1"
  • RndDCR = faint, decreased intensity or second color "2"
  • RndITL = italics "3"
  • RndUND = underlined "4"
  • RndBLN = slowly blinking (less than 150 per minute) "5"
  • RndNGT = negative image "7"
  • RndCNC = concealed data (hidden) "8"
Display colors
  • DspBLK = black display "30"
  • DspRED = red display "31"
  • DspGRN = green display "32"
  • DspYLW = yellow display "33"
  • DspBLE = blue display "34"
  • DspPRE = purple display "35"
  • DspCYN = cyan display "36"
  • DspWHT = white display "37"
Background colors
  • BckBLK = black background "40"
  • BckRED = red background "41"
  • BckGRN = green background "42"
  • BckYLW = yellow background "43"
  • BckBLE = blue background "44"
  • BckPRE = purple background "45"
  • BckCYN = cyan background "46"
  • BckWHT = white background "47"

Functions

  • Black(text string) string returns black text
  • Blue(text string) string returns blue text
  • Bold(text string) string returns bold text
  • Cyan(text string) string returns cyan text
  • Green(text string) string returns green text
  • Purple(text string) string returns purple text
  • Raw(rendition string, display string, background string, text string) string gives full control of the returned text by directly exposing all tokens. The constant section holds the ECMA-48 SGR - Select Graphic Rendition values but feel free to experiment and use your own values.
  • Red(text string) string returns red text
  • White(text string) string returns white text
  • Yellow(text string) string returns yellow text

Examples

// Print bold text
fmt.Println(text.Bold("Hello, world!"))

// Concatenate strings as usual
fmt.Println("Status is:", text.Green("OK"))

// You can make use of the exported constants to do fancy stuff with the Raw function.
// For example a blinking white BIG DANGER on red background:
fmt.Println(text.Raw(text.RndBLN, text.DspWHT, text.BckRED, "BIG DANGER"))

Credits

  • jc for the hint to use ANSI escape codes for text coloring
  • Windows console ANSI workaround from Azure/go-ansiterm

Contributing

When contributing to this project, please note our Code of Conduct.

License

The GNU General Public License v3.0 (GPLv3) - see LICENSE for more details

Documentation

Overview

Package text implements text manipulation for the command line.

Index

Examples

Constants

View Source
const (

	// rendition modes
	RndDFL = "0" // default rendition
	RndBLD = "1" // bold or increased intensity
	RndDCR = "2" // faint, decreased intensity or second color
	RndITL = "3" // italics
	RndUND = "4" // underlined
	RndBLN = "5" // slowly blinking (less than 150 per minute)
	RndNGT = "7" // negative image
	RndCNC = "8" // concealed data (hidden)
	// display colors
	DspBLK = "30" // black display
	DspRED = "31" // red display
	DspGRN = "32" // green display
	DspYLW = "33" // yellow display
	DspBLE = "34" // blue display
	DspPRE = "35" // purple display
	DspCYN = "36" // cyan display
	DspWHT = "37" // white display
	// background colors
	BckBLK = "40" // black background
	BckRED = "41" // red background
	BckGRN = "42" // green background
	BckYLW = "43" // yellow background
	BckBLE = "44" // blue background
	BckPRE = "45" // purple background
	BckCYN = "46" // cyan background
	BckWHT = "47" // white background
)

Variables

This section is empty.

Functions

func Black added in v0.2.0

func Black(text string) string

Black returns black text

Example
fmt.Println(Black("Black"))
Output:

func Blue added in v0.2.0

func Blue(text string) string

Blue returns blue text

Example
fmt.Println(Blue("Blue"))
Output:

func Bold

func Bold(text string) string

Bold returns bold text

Example
fmt.Println(Bold("Bold"))
Output:

func Cyan added in v0.2.0

func Cyan(text string) string

Cyan returns cyan text

Example
fmt.Println(Cyan("Cyan"))
Output:

func Green

func Green(text string) string

Green returns green text

Example
fmt.Println(Green("Green"))
Output:

func Purple added in v0.2.0

func Purple(text string) string

Purple returns purple text

Example
fmt.Println(Purple("Purple"))
Output:

func Raw added in v0.2.0

func Raw(rendition string, display string, background string, text string) string

Raw gives full control of the returned text by directly exposing all tokens. The constant section holds the ECMA-48 SGR - Select Graphic Rendition values but feel free to experiment and use your own values.

func Red

func Red(text string) string

Red returns red text

Example
fmt.Println(Red("Red"))
Output:

func White added in v0.2.0

func White(text string) string

White returns white text

Example
fmt.Println(White("White"))
Output:

func Yellow

func Yellow(text string) string

Yellow returns yellow text

Example
fmt.Println(Yellow("Yellow"))
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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