chalk

package module
v0.0.0-...-31c88e2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2015 License: Artistic-2.0 Imports: 2 Imported by: 3

README

go-chalk

A port of @sindresorhus' chalk library to golang. In node.js on windows libuv (nodes compatibility layer) automatically parses ANSI codes and calls the relevant Windows API to change the color. We don't get such niceties in golang so currently the functions simply noop on windows. I have plans to create an os.Stdout wrapper that will parse the ANSI codes but this is a very long term goal.

Install

go get github.com/danielchatfield/go-chalk

Usage

string msg = chalk.Cyan("some cyan text")

Documentation

Index

Constants

View Source
const ESC = "\x1b"

Escape is the terminal escape literal

Variables

This section is empty.

Functions

func Black

func Black(format string, a ...interface{}) string

Black returns the text with black foreground color

func Blue

func Blue(format string, a ...interface{}) string

Blue returns the text with blue foreground color

func Cyan

func Cyan(format string, a ...interface{}) string

Cyan returns the text with cyan foreground color

func Format

func Format(param Attribute, format string, a ...interface{}) string

Format formats the string with the given params

func Green

func Green(format string, a ...interface{}) string

Green returns the text with green foreground color

func Magenta

func Magenta(format string, a ...interface{}) string

Magenta returns the text with magenta foreground color

func Red

func Red(format string, a ...interface{}) string

Red returns the text with red foreground color

func White

func White(format string, a ...interface{}) string

White returns the text with white foreground color

func Yellow

func Yellow(format string, a ...interface{}) string

Yellow returns the text with yellow foreground color

Types

type Attribute

type Attribute int

Attribute defines the SGR codes

const (
	RESET Attribute = iota
	BOLD
	FAINT         // Not widely supported
	ITALIC        // Not widely supported
	UNDERLINE     //
	BLINKSLOW     // Less than 150 per min
	BLINKRAPID    // 150+ per minute
	NEGATIVE      // Swap foreground and background
	CONCEAL       // Not widely supported
	STRIKETHROUGH // Not widely supported
)

SGR parameters as specified here: http://en.wikipedia.org/wiki/ANSI_escape_code

const (
	FOREGROUND Attribute = 30
	BACKGROUND Attribute = 40
	INTENSE    Attribute = 60
)

Foreground, background, and intense offset

const (
	BLACK Attribute = iota
	RED
	GREEN
	YELLOW
	BLUE
	MAGENTA
	CYAN
	WHITE
)

Colors

type Formatter

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

Formatter represents a formatter with a list of attributes to apply

func NewFormatter

func NewFormatter(value ...Attribute) *Formatter

NewFormatter returns a new Formatter with the given params

func (*Formatter) Add

func (f *Formatter) Add(value ...Attribute) *Formatter

Add adds an attribute to the formatter

Jump to

Keyboard shortcuts

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