color

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2020 License: MIT Imports: 6 Imported by: 4

README

goulash/color

GoDoc

Package color provides routines for printing ANSI color codes.

For more information, see the documentation! :-)

This package is licensed under the MIT license.

Documentation

Overview

Package color provides printing in ANSI colors.

TODO: Need to document this. See the Color function for now.

This package uses code from github.com/wsxiaoys/terminal(https://github.com/wsxiaoys/terminal). Many thanks.

Index

Constants

View Source
const ColorReset = "\033[0m"

ColorReset is the string that resets the text to default style.

Variables

View Source
var ErrInvalidEscape = errors.New("invalid escape rune")

ErrInvalidEscape is an error that is used when the parser panics.

View Source
var ErrUnexpectedEOF = errors.New("unexpected EOF while parsing")

Functions

func Color

func Color(s string, escape rune) string

Color translates a string into an escaped string.

This example will output the text with a Blue foreground and a Black background

color.Println("@{bK}Example Text")

This one will output the text with a red foreground

color.Println("@rExample Text")

This one will escape the @

color.Println("@@")

Full color syntax code

@{rgbcmykwRGBCMYKW}  foreground/background color
  r/R:  Red
  g/G:  Green
  b/B:  Blue
  c/C:  Cyan
  m/M:  Magenta
  y/Y:  Yellow
  k/K:  Black
  w/W:  White
@{|}  Reset format style
@{!./_} Bold / Dim / Italic / Underline
@{^&} Blink / Fast blink
@{?} Reverse the foreground and background color
@{-} Hide the text

Note some of the functions are not widely supported, like "Fast blink" and "Italic".

func ColorCode

func ColorCode(s string) string

ColorCode compiles a color syntax string like "rG" to escape code.

func Decolor

func Decolor(s string, escape rune) string

Decolor cleans a string of @x color codes.

func Uncolor

func Uncolor(s string) string

Uncolor cleans a string of ANSI color codes.

Types

type Colorizer

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

func New

func New() *Colorizer

func (*Colorizer) Color

func (c *Colorizer) Color(s string) string

func (*Colorizer) Enabled

func (c *Colorizer) Enabled() bool

func (*Colorizer) EscapeChar

func (c *Colorizer) EscapeChar() rune

func (*Colorizer) Fprint

func (c *Colorizer) Fprint(w io.Writer, a ...interface{}) (int, error)

func (*Colorizer) Fprintf

func (c *Colorizer) Fprintf(w io.Writer, format string, a ...interface{}) (int, error)

func (*Colorizer) Fprintln

func (c *Colorizer) Fprintln(w io.Writer, a ...interface{}) (int, error)

func (*Colorizer) Print

func (c *Colorizer) Print(a ...interface{}) (int, error)

func (*Colorizer) Printf

func (c *Colorizer) Printf(format string, a ...interface{}) (int, error)

func (*Colorizer) Println

func (c *Colorizer) Println(a ...interface{}) (int, error)

func (*Colorizer) Set

func (c *Colorizer) Set(s string) (err error)

Set sets c on or off, with s one of "auto", "always", or "never", otherwise an error is returned.

Note: if "auto" is passed, and SetOutput was passed an io.Writer that is not an *os.File, nothing will happen. This lets you decide whether you want it to fall back to enabled or disabled.

func (*Colorizer) SetEnabled

func (c *Colorizer) SetEnabled(b bool)

func (*Colorizer) SetEscapeChar

func (c *Colorizer) SetEscapeChar(r rune)

SetEscapeChar sets the escape character, which can be one of the following characters:

@ * + = ~

If it is none of these characters, then this function panics with ErrInvalidEscape.

func (*Colorizer) SetFile

func (c *Colorizer) SetFile(f *os.File)

func (*Colorizer) SetOutput

func (c *Colorizer) SetOutput(w io.Writer)

func (*Colorizer) Sprint

func (c *Colorizer) Sprint(a ...interface{}) string

func (*Colorizer) Sprintf

func (c *Colorizer) Sprintf(format string, a ...interface{}) string

func (*Colorizer) Sprintln

func (c *Colorizer) Sprintln(a ...interface{}) string

func (Colorizer) String

func (c Colorizer) String() string

String returns the current state, either always or never.

func (Colorizer) Type

func (c Colorizer) Type() string

Returns the name of the type: "Colorizer".

TODO: This is implemented to fulfil the github.com/spf13/pflag.Value interface. It's not very well documented what this is for however.

Jump to

Keyboard shortcuts

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