golor

package module
v0.0.0-...-642e804 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2013 License: MIT Imports: 3 Imported by: 1

README

golor

golor is a terminal color package for Go, supporting both 16-colors mode and 256 colors mode.

Example usage

16-bit color printing:

// See examples/colors.go
fmt.Println(golor.Colorize("Green foreground", golor.G, -1))
fmt.Println(golor.Colorize("Cyan background", -1, golor.CYAN))

256-color printing:

// See examples/colors.go
index := 42  // index can vary from 0 to 255
fmt.Println(golor.Colorize("Foreground", index, -1))

Consistently assigning unique colors to strings:

// See examples/unique.go
name := "srid"
fmt.Println(golor.Colorize(process, golor.AssignColor(name), -1))

Documentation

Overview

256 color terminal printing in Go.

Index

Constants

This section is empty.

Variables

View Source
var MIN, MAX int
View Source
var R, G, C, M, Y, W int
View Source
var RED, GREEN, BLUE, CYAN, MAGENTA, YELLOW, BLACK, WHITE, GRAY int

16-colors

Functions

func AssignColor

func AssignColor(s string) int

func Colorize

func Colorize(s string, fg int, bg int) string

func RGB

func RGB(red, green, blue int) int

Types

type Legacy

type Legacy struct {
}

Legacy terminal supporting only 16 colors.

func (*Legacy) AssignColor

func (t *Legacy) AssignColor(s string) int

func (*Legacy) Colorize

func (t *Legacy) Colorize(s string, fg int, bg int) string

func (*Legacy) RGB

func (t *Legacy) RGB(red, green, blue int) int

RGB returns the color code corresponding a RGB value set. Arguments must range from 0 to 5. Returned values range from 16 (black) to 231 (white).

type Terminal

type Terminal interface {
	// RGB returns the color code corresponding a RGB value set.
	RGB(red, green, blue int) int
	Colorize(s string, fg int, bg int) string
	// Assign and return an unique color for this string. Automatically
	// avoid black/white colors.
	AssignColor(s string) int
}
var TERM Terminal

type Xterm256

type Xterm256 struct {
}

func (*Xterm256) AssignColor

func (t *Xterm256) AssignColor(s string) int

func (*Xterm256) Colorize

func (t *Xterm256) Colorize(s string, fg int, bg int) string

func (*Xterm256) RGB

func (t *Xterm256) RGB(red, green, blue int) int

RGB returns the color code corresponding a RGB value set. Arguments must range from 0 to 5. Returned values range from 16 (black) to 231 (white).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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