xcolor

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2021 License: MIT Imports: 6 Imported by: 4

README

xcolor

Dependencies

  • testing*

Documents

Types
  • type Style uint8
  • type Color uint8
  • type Background uint8
  • type MixCode []uint8
Variables
  • None
Constants
  • const Bold Style
  • const Faint Style
  • const Italic Style
  • const Underline Style
  • const Reverse Style
  • const Strikethrough Style
  • const Black Color
  • const Red Color
  • const Green Color
  • const Yellow Color
  • const Blue Color
  • const Magenta Color
  • const Cyan Color
  • const White Color
  • const Default Color
  • const BrightBlack Color
  • const BrightRed Color
  • const BrightGreen Color
  • const BrightYellow Color
  • const BrightBlue Color
  • const BrightMagenta Color
  • const BrightCyan Color
  • const BrightWhite Color
  • const BGBlack Background
  • const BGRed Background
  • const BGGreen Background
  • const BGYellow Background
  • const BGBlue Background
  • const BGMagenta Background
  • const BGCyan Background
  • const BGWhite Background
  • const BGDefault Background
  • const BGBrightBlack Background
  • const BGBrightRed Background
  • const BGBrightGreen Background
  • const BGBrightYellow Background
  • const BGBrightBlue Background
  • const BGBrightMagenta Background
  • const BGBrightCyan Background
  • const BGBrightWhite Background
  • const FullTpl string
Functions
  • func InitTerminal(out io.Writer) bool
  • func ForceColor()
Methods
  • func (s Style) String() string
  • func (s Style) Code() string
  • func (s Style) WithStyle(s2 Style) MixCode
  • func (s Style) WithColor(c Color) MixCode
  • func (s Style) WithBackground(b Background) MixCode
  • func (s Style) Print(a ...interface{})
  • func (s Style) Printf(format string, a ...interface{})
  • func (s Style) Println(a ...interface{})
  • func (s Style) Sprint(a ...interface{}) string
  • func (s Style) Sprintf(format string, a ...interface{}) string
  • func (s Style) Sprintln(a ...interface{}) string
  • func (s Style) Fprint(w io.Writer, a ...interface{}) (n int, err error)
  • func (s Style) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)
  • func (s Style) Fprintln(w io.Writer, a ...interface{}) (n int, err error)
  • func (c Color) String() string
  • func (c Color) Code() string
  • func (c Color) WithStyle(s Style) MixCode
  • func (c Color) WithBackground(b Background) MixCode
  • func (c Color) Print(a ...interface{})
  • func (c Color) Printf(format string, a ...interface{})
  • func (c Color) Println(a ...interface{})
  • func (c Color) Sprint(a ...interface{}) string
  • func (c Color) Sprintf(format string, a ...interface{}) string
  • func (c Color) Sprintln(a ...interface{}) string
  • func (c Color) Fprint(w io.Writer, a ...interface{}) (n int, err error)
  • func (c Color) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)
  • func (c Color) Fprintln(w io.Writer, a ...interface{}) (n int, err error)
  • func (b Background) String() string
  • func (b Background) Code() string
  • func (b Background) WithStyle(s Style) MixCode
  • func (b Background) WithColor(c Color) MixCode
  • func (b Background) Print(a ...interface{})
  • func (b Background) Printf(format string, a ...interface{})
  • func (b Background) Println(a ...interface{})
  • func (b Background) Sprint(a ...interface{}) string
  • func (b Background) Sprintf(format string, a ...interface{}) string
  • func (b Background) Sprintln(a ...interface{}) string
  • func (b Background) Fprint(w io.Writer, a ...interface{}) (n int, err error)
  • func (b Background) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)
  • func (b Background) Fprintln(w io.Writer, a ...interface{}) (n int, err error)
  • func (m MixCode) String() string
  • func (m MixCode) Codes() []uint8
  • func (m MixCode) WithStyle(s Style) MixCode
  • func (m MixCode) WithColor(c Color) MixCode
  • func (m MixCode) WithBackground(b Background) MixCode
  • func (m MixCode) Print(a ...interface{})
  • func (m MixCode) Printf(format string, a ...interface{})
  • func (m MixCode) Println(a ...interface{})
  • func (m MixCode) Sprint(a ...interface{}) string
  • func (m MixCode) Sprintf(format string, a ...interface{}) string
  • func (m MixCode) Sprintln(a ...interface{}) string
  • func (m MixCode) Fprint(w io.Writer, a ...interface{}) (n int, err error)
  • func (m MixCode) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)
  • func (m MixCode) Fprintln(w io.Writer, a ...interface{}) (n int, err error)

Documentation

Index

Constants

View Source
const FullTpl = "\x1b[%sm%s\x1b[0m"

FullTpl represents the ANSI escape code template. That is ESC[X,Ym ... ESC[0m

Variables

This section is empty.

Functions

func ForceColor

func ForceColor()

ForceColor initializes os.Stdout and os.Stderr to support ANSI escape code.

func InitTerminal

func InitTerminal(out io.Writer) bool

InitTerminal initializes the given io.Writer to support ANSI escape code. Notice that io.Writer must be an os.File.

Types

type Background added in v1.5.0

type Background uint8

Background represents a background color code. See https://en.wikipedia.org/wiki/ANSI_escape_code#Colors for details.

const (
	BGBlack   Background = iota + 40 // Background for black, 40.
	BGRed                            // Background for red, 41.
	BGGreen                          // Background for green, 42.
	BGYellow                         // Background for yellow, 43.
	BGBlue                           // Background for blue, 44.
	BGMagenta                        // Background for magenta, 45.
	BGCyan                           // Background for cyan, 46.
	BGWhite                          // Background for white, 47.
	BGDefault Background = 49        // Background for default, 49.
)
const (
	BGBrightBlack   Background = iota + 100 // Background for bright black, 100.
	BGBrightRed                             // Background for bright red, 101.
	BGBrightGreen                           // Background for bright green, 102.
	BGBrightYellow                          // Background for bright yellow, 103.
	BGBrightBlue                            // Background for bright blue, 104.
	BGBrightMagenta                         // Background for bright magenta, 105.
	BGBrightCyan                            // Background for bright cyan, 106.
	BGBrightWhite                           // Background for bright white, 107.
)

func (Background) Code added in v1.5.0

func (b Background) Code() uint8

Code returns the number value of the code.

func (Background) Fprint added in v1.5.0

func (b Background) Fprint(w io.Writer, a ...interface{}) (n int, err error)

Fprint writes the colored string to io.Writer, with the given Background.

func (Background) Fprintf added in v1.5.0

func (b Background) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)

Fprintf formats and writes the colored string to io.Writer, with the given Background.

func (Background) Fprintln added in v1.5.0

func (b Background) Fprintln(w io.Writer, a ...interface{}) (n int, err error)

Fprintln writes the colored string and a newline to io.Writer, with the given Background.

func (Background) Print added in v1.5.0

func (b Background) Print(a ...interface{})

Print prints the colored string, with the given Background.

func (Background) Printf added in v1.5.0

func (b Background) Printf(format string, a ...interface{})

Printf formats and prints the colored string, with the given Background.

func (Background) Println added in v1.5.0

func (b Background) Println(a ...interface{})

Println prints the colored string and a newline, with the given Background.

func (Background) Sprint added in v1.5.0

func (b Background) Sprint(a ...interface{}) string

Sprint returns the colored string, with the given Background.

func (Background) Sprintf added in v1.5.0

func (b Background) Sprintf(format string, a ...interface{}) string

Sprintf formats and returns the colored string, with the given Background.

func (Background) Sprintln added in v1.5.0

func (b Background) Sprintln(a ...interface{}) string

Sprintln returns the colored string and a newline, with the given Background.

func (Background) String added in v1.5.0

func (b Background) String() string

String returns the string value of the code.

func (Background) WithColor added in v1.5.0

func (b Background) WithColor(c Color) MixCode

WithColor creates a MixCode with Background and Color.

func (Background) WithStyle added in v1.5.0

func (b Background) WithStyle(s Style) MixCode

WithStyle creates a MixCode with Background and Style.

type Color

type Color uint8

Color represents a color code. See https://en.wikipedia.org/wiki/ANSI_escape_code#Colors for details.

const (
	Black   Color = iota + 30 // Color for black, 30.
	Red                       // Color for red, 31.
	Green                     // Color for green, 32.
	Yellow                    // Color for yellow, 33.
	Blue                      // Color for blue, 34.
	Magenta                   // Color for magenta, 35.
	Cyan                      // Color for cyan, 36.
	White                     // Color for white, 37.
	Default Color = 39        // Color for default, 39.
)
const (
	BrightBlack   Color = iota + 90 // Color for bright black, 90.
	BrightRed                       // Color for bright red, 91.
	BrightGreen                     // Color for bright green, 92.
	BrightYellow                    // Color for bright yellow, 93.
	BrightBlue                      // Color for bright blue, 94.
	BrightMagenta                   // Color for bright magenta, 95.
	BrightCyan                      // Color for bright cyan, 96.
	BrightWhite                     // Color for bright white, 97.
)

func (Color) Code

func (c Color) Code() uint8

Code returns the number value of the code.

func (Color) Fprint added in v1.5.0

func (c Color) Fprint(w io.Writer, a ...interface{}) (n int, err error)

Fprint writes the colored string to io.Writer, with the given Color.

func (Color) Fprintf added in v1.5.0

func (c Color) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)

Fprintf formats and writes the colored string to io.Writer, with the given Color.

func (Color) Fprintln added in v1.5.0

func (c Color) Fprintln(w io.Writer, a ...interface{}) (n int, err error)

Fprintln writes the colored string and a newline to io.Writer, with the given Color.

func (Color) Print

func (c Color) Print(a ...interface{})

Print prints the colored string, with the given Color.

func (Color) Printf

func (c Color) Printf(format string, a ...interface{})

Printf formats and prints the colored string, with the given Color.

func (Color) Println

func (c Color) Println(a ...interface{})

Println prints the colored string and a newline, with the given Color.

func (Color) Sprint

func (c Color) Sprint(a ...interface{}) string

Sprint returns the colored string, with the given Color.

func (Color) Sprintf

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

Sprintf formats and returns the colored string, with the given Color.

func (Color) Sprintln

func (c Color) Sprintln(a ...interface{}) string

Sprintln returns the colored string and a newline, with the given Color.

func (Color) String

func (c Color) String() string

String returns the string value of the code.

func (Color) WithBackground added in v1.5.0

func (c Color) WithBackground(b Background) MixCode

WithBackground creates a MixCode with Color and Background.

func (Color) WithStyle added in v1.5.0

func (c Color) WithStyle(s Style) MixCode

WithStyle creates a MixCode with Color and Style.

type MixCode added in v1.5.0

type MixCode []uint8

MixCode represents an ANSI escape code, has mix styles in Style, Color and Background. See https://en.wikipedia.org/wiki/ANSI_escape_code and https://tforgione.fr/posts/ansi-escape-codes/ for details.

func (MixCode) Codes added in v1.5.0

func (m MixCode) Codes() []uint8

Codes returns the number value of the code.

func (MixCode) Fprint added in v1.5.0

func (m MixCode) Fprint(w io.Writer, a ...interface{}) (n int, err error)

Fprint writes the styled and colored string to io.Writer, with the given MixCode.

func (MixCode) Fprintf added in v1.5.0

func (m MixCode) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)

Fprintf formats and writes the styled and colored string to io.Writer, with the given MixCode.

func (MixCode) Fprintln added in v1.5.0

func (m MixCode) Fprintln(w io.Writer, a ...interface{}) (n int, err error)

Fprintln writes the styled and colored string and a newline to io.Writer, with the given MixCode.

func (MixCode) Print added in v1.5.0

func (m MixCode) Print(a ...interface{})

Print prints the styled and colored string, with the given MixCode.

func (MixCode) Printf added in v1.5.0

func (m MixCode) Printf(format string, a ...interface{})

Printf formats and prints the styled and colored string, with the given MixCode.

func (MixCode) Println added in v1.5.0

func (m MixCode) Println(a ...interface{})

Println prints the styled and colored string and a newline, with the given MixCode.

func (MixCode) Sprint added in v1.5.0

func (m MixCode) Sprint(a ...interface{}) string

Sprint returns the styled and colored string, with the given MixCode.

func (MixCode) Sprintf added in v1.5.0

func (m MixCode) Sprintf(format string, a ...interface{}) string

Sprintf formats and returns the styled and colored string, with the given MixCode.

func (MixCode) Sprintln added in v1.5.0

func (m MixCode) Sprintln(a ...interface{}) string

Sprintln returns the styled and colored string and a newline, with the given MixCode.

func (MixCode) String added in v1.5.0

func (m MixCode) String() string

String returns the string value of the code.

func (MixCode) WithBackground added in v1.5.0

func (m MixCode) WithBackground(b Background) MixCode

WithBackground creates a new MixCode with MixCode and Background.

func (MixCode) WithColor added in v1.5.0

func (m MixCode) WithColor(c Color) MixCode

WithColor creates a new MixCode with MixCode and Color.

func (MixCode) WithStyle added in v1.5.0

func (m MixCode) WithStyle(s Style) MixCode

WithStyle creates a new MixCode with MixCode and Style.

type Style added in v1.5.0

type Style uint8

Style represents a style code. See https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters for details.

const (
	Bold          Style = iota + 1 // Style for bold, 1.
	Faint                          // Style for faint, 2.
	Italic                         // Style for italic, 3.
	Underline                      // Style for underline, 4.
	Reverse       Style = 7        // Style for reverse, 7.
	Strikethrough Style = 9        // Style for strikethrough, 9.
)

func (Style) Code added in v1.5.0

func (s Style) Code() uint8

Code returns the number value of the code.

func (Style) Fprint added in v1.5.0

func (s Style) Fprint(w io.Writer, a ...interface{}) (n int, err error)

Fprint writes the styled string to io.Writer, with the given Style.

func (Style) Fprintf added in v1.5.0

func (s Style) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)

Fprintf formats and writes the styled string to io.Writer, with the given Style.

func (Style) Fprintln added in v1.5.0

func (s Style) Fprintln(w io.Writer, a ...interface{}) (n int, err error)

Fprintln writes the styled string and a newline to io.Writer, with the given Style.

func (Style) Print added in v1.5.0

func (s Style) Print(a ...interface{})

Print prints the styled string, with the given Style.

func (Style) Printf added in v1.5.0

func (s Style) Printf(format string, a ...interface{})

Printf formats and prints the styled string, with the given Style.

func (Style) Println added in v1.5.0

func (s Style) Println(a ...interface{})

Println prints the styled string and a newline, with the given Style.

func (Style) Sprint added in v1.5.0

func (s Style) Sprint(a ...interface{}) string

Sprint returns the styled string, with the given Style.

func (Style) Sprintf added in v1.5.0

func (s Style) Sprintf(format string, a ...interface{}) string

Sprintf formats and returns the styled string, with the given Style.

func (Style) Sprintln added in v1.5.0

func (s Style) Sprintln(a ...interface{}) string

Sprintln returns the styled string and a newline, with the given Style.

func (Style) String added in v1.5.0

func (s Style) String() string

String returns the string value of the code.

func (Style) WithBackground added in v1.5.0

func (s Style) WithBackground(b Background) MixCode

WithBackground creates a MixCode with Style and Background.

func (Style) WithColor added in v1.5.0

func (s Style) WithColor(c Color) MixCode

WithColor creates a MixCode with Style and Color.

func (Style) WithStyle added in v1.5.0

func (s Style) WithStyle(s2 Style) MixCode

WithStyle creates a MixCode with multiple Style.

Jump to

Keyboard shortcuts

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