Categorygithub.com/jcwillox/emerald
modulepackage
0.3.3
Repository: https://github.com/jcwillox/emerald.git
Documentation: pkg.go.dev

# README

Emerald

A basic color library for use in my Go projects, built on top of mgutz/ansi.

Package ansi is a small, fast library to create ANSI colored strings and codes.

Install

Get it

go get -u github.com/jcwillox/emerald

Example

import "github.com/jcwillox/emerald"

// colorize a string, SLOW
msg := emerald.Color("foo", "red+b:white")

// create a FAST closure function to avoid computation of ANSI code
phosphorize := emerald.ColorFunc("green+h:black")
msg = phosphorize("Bring back the 80s!")
msg2 := phospohorize("Look, I'm a CRT!")

// cache escape codes and build strings manually
lime := emerald.ColorCode("green+h:black")
reset := emerald.ColorCode("reset")

fmt.Println(lime, "Bring back the 80s!", reset)

Other examples

Color(s, "red")            // red
Color(s, "red+d")          // red dim
Color(s, "red+b")          // red bold
Color(s, "red+B")          // red blinking
Color(s, "red+u")          // red underline
Color(s, "red+bh")         // red bold bright
Color(s, "red:white")      // red on white
Color(s, "red+b:white+h")  // red bold on white bright
Color(s, "red+B:white+h")  // red blink on white bright
Color(s, "off")            // turn off ansi codes

To view color combinations, from project directory in terminal.

go test

Style format

"foregroundColor+attributes:backgroundColor+attributes"

Colors

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • 0...255 (256 colors)
  • #FFFFFF (hex color codes)

Foreground Attributes

  • B = Blink
  • b = bold
  • h = high intensity (bright)
  • d = dim
  • i = inverse
  • s = strikethrough
  • u = underline

Background Attributes

  • h = high intensity (bright)

Constants

  • emerald.Reset
  • emerald.DefaultBG
  • emerald.DefaultFG
  • emerald.Black
  • emerald.Red
  • emerald.Green
  • emerald.Yellow
  • emerald.Blue
  • emerald.Magenta
  • emerald.Cyan
  • emerald.White
  • emerald.LightBlack
  • emerald.LightRed
  • emerald.LightGreen
  • emerald.LightYellow
  • emerald.LightBlue
  • emerald.LightMagenta
  • emerald.LightCyan
  • emerald.LightWhite

Windows Support

Emerald has full support for Windows and has print functions that wrap mattn/go-colorable to handle ANSI support on older windows systems.

import (
    "github.com/jcwillox/emerald"
)

emerald.Print(emerald.Blue)
emerald.Printf("%s%s", emerald.Blue, "Hello World")
emerald.Println(emerald.Blue, "Hello World", Reset)

References

Wikipedia ANSI escape codes Colors

General tips and formatting

# Packages

No description provided by the author

# Functions

AutoSetColorState automatically SetColorState based on the whether we are outputting to a terminal or the environment variables.
Color colors a string based on the ANSI color code for style.
ColorCode returns the ANSI color code for style.
ColorFunc creates a closure to avoid computation ANSI color code.
ColorFuncVar creates a closure to avoid computation ANSI color code and returns ANSI sequence.
ColorIndexBg convert 256 color code to ANSI background color.
ColorIndexFg convert 256 color code to ANSI foreground color.
No description provided by the author
ColorPreference returns the color preference based on the environment variables.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
IsColorTerm combines IsColor and IsTerminal.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
IsTerminal returns true if stdout is attached to a terminal.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
SetColorState enables or disables ANSI support in the library using this function is preferred to directly setting `ColorEnabled` as it allows us to perform other actions.
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

Black FG.
Blue FG.
Bold FG.
No description provided by the author
Colors maps common color names to their ANSI color code.
No description provided by the author
No description provided by the author
No description provided by the author
Cyan FG.
DefaultBG is the default background.
DefaultFG is the default foreground.
No description provided by the author
No description provided by the author
Green FG.
No description provided by the author
No description provided by the author
LightBlack FG.
LightBlue FG.
LightCyan FG.
LightGreen FG.
LightMagenta FG.
LightRed FG.
LightWhite FG.
LightYellow FG.
No description provided by the author
Magenta FG.
No description provided by the author
Red FG.
Reset is the ANSI reset escape sequence.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
White FG.
Yellow FG.

# Structs

No description provided by the author
No description provided by the author

# Type aliases

Colorizer takes an input string and colorizes it based on the style it was created with.
No description provided by the author