color

package module
v0.0.0-...-28ad4cc Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2014 License: MIT Imports: 0 Imported by: 28

README

This library is boring, use rgbterm

Package color

Colorize your terminal strings.

fmt.Printf("I'm in a %s world!\n", brush.Blue("blue"))

Usage

Default Brush are available for your convenience. You can invoke them directly

fmt.Printf("This is %s\n", brush.Red("red"))

... or you can create new ones!

weird := color.NewBrush(color.PurplePaint, color.CyanPaint)
fmt.Printf("This color is %s\n", weird("weird"))

Create a Style, which has some convenience methods :

redBg := color.NewStyle(color.RedPaint, color.YellowPaint)

Style.WithForeground or WithBackground returns a new Style, with the applied Paint. Styles are immutable so the original one is left unchanged

greenFg := redBg.WithForeground(color.GreenPaint)

// Style.Brush gives you a Brush that you can invoke directly to colorize strings.
green := greenFg.Brush()
fmt.Printf("This is %s but not really\n", green("kind of green"))

You can use it with all sorts of things :

sout := log.New(os.Stdout, "["+brush.Green("OK").String()+"]\t", log.LstdFlags)
serr := log.New(os.Stderr, "["+brush.Red("OMG").String()+"]\t", log.LstdFlags)

sout.Printf("Everything was going %s until...", brush.Cyan("fine"))
serr.Printf("%s killed %s !!!", brush.Red("Locke"), brush.Blue("Jacob"))

That's it!

Demo

A coloured terminal

Docs

GoDoc! (↫ this is a link)

FAQ

Does it work on Windows?

NO!

It's spelled "colour"

NO!

You're canadian, spell it "colour"

NO!

Documentation

Overview

Package color colorizes your terminal strings.

Default Brush are available in sub-package brush for your convenience. You can invoke them directly:

fmt.Printf("This is %s\n", brush.Red("red"))

...or you can create new ones!

weird := color.NewBrush(color.PurplePaint, color.CyanPaint)
fmt.Printf("This color is %s\n", weird("weird"))

Create a Style, which has convenience methods :

redBg := color.NewStyle(color.RedPaint, color.YellowPaint)

Style.WithForeground or WithBackground returns a new Style, with the applied Paint. Styles are immutable so the original one is left unchanged :

greenFg := redBg.WithForeground(color.GreenPaint)

Style.Brush gives you a Brush that you can invoke directly to colorize strings :

green := greenFg.Brush()
fmt.Printf("This is %s but not really\n", green("kind of green"))

You can use it with all sorts of things :

sout := log.New(os.Stdout, "["+brush.Green("OK").String()+"]\t", log.LstdFlags)
serr := log.New(os.Stderr, "["+brush.Red("OMG").String()+"]\t", log.LstdFlags)

sout.Printf("Everything was going %s until...", brush.Cyan("fine"))
serr.Printf("%s killed %s !!!", brush.Red("Locke"), brush.Blue("Jacob"))

That's it!

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Brush

type Brush func(string) string

Brush is a function that let's you colorize strings directly.

func NewBrush

func NewBrush(background, foreground Paint) Brush

NewBrush gives you a brush that you can invoke directly to create colorized strings

type Paint

type Paint string

Paint is a color to paint, either as a foreground or background paint

const (
	BlackPaint      Paint = `0;30`
	DarkRedPaint    Paint = `0;31`
	DarkGreenPaint  Paint = `0;32`
	DarkYellowPaint Paint = `0;33`
	DarkBluePaint   Paint = `0;34`
	DarkPurplePaint Paint = `0;35`
	DarkCyanPaint   Paint = `0;36`
	LightGrayPaint  Paint = `0;37`

	DarkGrayPaint Paint = `1;30`
	RedPaint      Paint = `1;31`
	GreenPaint    Paint = `1;32`
	YellowPaint   Paint = `1;33`
	BluePaint     Paint = `1;34`
	PurplePaint   Paint = `1;35`
	CyanPaint     Paint = `1;36`
	WhitePaint    Paint = `1;37`
)

Valid colors for ANSI terminals

type Style

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

Style will give you colorized strings. Styles are immutable.

func NewStyle

func NewStyle(background, foreground Paint) Style

NewStyle gives you a style ready to produce strings with the given background and foreground colors

func (Style) Brush

func (s Style) Brush() Brush

Brush is a function that can be used to color things directly, i.e:

red := NewStyle(BlackPaint, RedPaint).Brush()
fmt.Printf("This is %s\n", red("red"))

func (Style) WithBackground

func (s Style) WithBackground(color Paint) Style

WithBackground copies the current style and return a new Style that has the desired background. The original Style is unchanged and you must capture the return value.

func (Style) WithForeground

func (s Style) WithForeground(color Paint) Style

WithForeground copies the current style and return a new Style that has the desired foreground. The original Style is unchanged and you must capture the return value.

Directories

Path Synopsis
Package brush provides convenience types to use Brush types as plain strings.
Package brush provides convenience types to use Brush types as plain strings.

Jump to

Keyboard shortcuts

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