Simple library to handle ANSI functions and parsing of color formatting strings

Related tags

Utilities emerald
Overview

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

You might also like...
Color generator with golang
Color generator with golang

color-generator How to use this repo img src="https://color-pallete-gen.herokuapp.com/hexCode" / Like this: Getting Started Copy sample.env to .env

Wl-gammarelay - Wayland utility for changing color temperature using hotkeys

wl-gammarelay This utility was developed from gammastep, a fork of redshift as w

Easy to use open source hardware to drive WS2811 LEDs with high-quality color

STOP DOING FADECANDY LEDs were not supposed to be given data pins YEARS of "temporal dithering" but no real-world use found for having more than three

A small & fast dependency-free library for parsing micro expressions.

MicroExpr A small & fast dependency-free library for parsing micro expressions. This library was originally built for use in templating languages (e.g

A utility library to do files/io/bytes processing/parsing in file-system or network.

goreader A utility library to do files/io/bytes processing/parsing in file-system or network. These features are really common to be implemented for a

This library provides an ASTERIX Frame(binary data) decoding/parsing(json,xml) capabilities for Go.

GoAsterix This library provides an ASTERIX Frame(binary data) decoding/parsing(json,xml) capabilities for Go. ASTERIX ASTERIX (All Purpose Structured

A super simple Lodash like utility library with essential functions that empowers the development in Go
A super simple Lodash like utility library with essential functions that empowers the development in Go

A simple Utility library for Go Go does not provide many essential built in functions when it comes to the data structure such as slice and map. This

Go-path - A helper package that provides utilities for parsing and using ipfs paths

go-path is a helper package that provides utilities for parsing and using ipfs paths

Golang source code parsing, usage like reflect package

gotype Golang source code parsing, usage like reflect package English 简体中文 Usage API Documentation Examples License Pouch is licensed under the MIT Li

Releases(v0.3.3)
  • v0.3.3(Feb 25, 2022)

  • v0.3.2(Jan 20, 2022)

  • v0.3.1(Nov 15, 2021)

    • Add controlled Bold sequence (71ccfb5acd13eee691b8572cac90e1a79f54b992)
    • Fix plain mode for highlighters (7742d9a319d19e065d8ddc859bcaf7d5a8936454)
    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Nov 13, 2021)

    • Improve performance of ANSI conversions (4811e12d33ffdbbe1ccfbbbe87a12c9a54f32130)
    • Make other ANSI sequences change based on color mode (a5503e7c899c754a86797e93f38b992bed97f61d)
    • Add basic benchmarks (1d853cbab6177b125979d5f98d3efa09a38d2129)
    • Add highlight file and path functions (60e056cd3e5646656f066ac35ea56f2b59344f86)
    • Add highlight file mode function (3f7508ab69230003c4494c8e35ffe51e86936d00)
    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Nov 5, 2021)

    • Add Colorizer type for ColorFunc return (b11e704dac36a8e14751996c2b7e259ec57e495e)
    • Bump dependencies (7eb2b5a71a141bd3a82a2f801a18d909970d9d62)
    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Nov 5, 2021)

Owner
Josh Willox
Josh Willox
Color lets you use colorized outputs in terms of ANSI Escape Codes in Go (Golang)

Color lets you use colorized outputs in terms of ANSI Escape Codes in Go (Golang). It has support for Windows too! The API can be used in several ways, pick one that suits you.

Sensio 0 Feb 5, 2022
COCO (Color Converter) is a color conversion library for Go.

COCO (Color Converter) for Go COCO (Color Converter) is a color conversion library for Go. Heavily inspired by NPM's color-convert. It converts all wa

Hisam Fahri 6 Oct 4, 2022
A program to create assembly 8086 strings to print without using any printing/strings related function but only mov-xchg-int and loops

Assembly String builder tool A program to create assembly 8086 strings to print without using any printing/strings related function but only mov-xchg-

Reg 2 Feb 1, 2022
randstr is a module that contains functions for generating random strings.

randstr is a module that contains functions for generating random strings. The functions in this module uses the crypto/rand package. Installa

Henrik Christensen 3 Nov 13, 2021
A color manipulation and conversion library for Go. 🌈 ✨

Khroma Khroma is a color manipulation and conversion library for Go. ✨ ?? Example package main import ( "log" "github.com/qbee-org/khroma" ) func

QBee 2 May 30, 2022
Raw ANSI sequence helpers

Raw ANSI sequence helpers

Christian Muehlhaeuser 17 Oct 23, 2022
Simple go package which converts roman strings to integer

romanparse Simple go package which converts roman strings

Caio Ribeiro Pereira 4 Aug 11, 2022
A Go (golang) library for parsing and verifying versions and version constraints.

go-version is a library for parsing versions and version constraints, and verifying versions against a set of constraints. go-version can sort a collection of versions properly, handles prerelease/beta versions, can increment versions, etc.

HashiCorp 1.3k Jan 9, 2023
Go package to generate and manage color palettes & schemes 🎨

Go package to generate and manage color palettes & schemes

Christian Muehlhaeuser 503 Dec 29, 2022
Molecule is a Go library for parsing protobufs in an efficient and zero-allocation manner

Molecule Molecule is a Go library for parsing protobufs in an efficient and zero-allocation manner. The API is loosely based on this excellent Go JSON

Richard Artoul 376 Jan 5, 2023