Documentation ¶
Index ¶
- Constants
- func ForceColor()
- func InitTerminal(out io.Writer) bool
- type Background
- func (b Background) Code() uint8
- 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 (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) String() string
- func (b Background) WithColor(c Color) MixCode
- func (b Background) WithStyle(s Style) MixCode
- type Color
- func (c Color) Code() uint8
- 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 (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) String() string
- func (c Color) WithBackground(b Background) MixCode
- func (c Color) WithStyle(s Style) MixCode
- type MixCode
- func (m MixCode) Codes() []uint8
- 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)
- 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) String() string
- func (m MixCode) WithBackground(b Background) MixCode
- func (m MixCode) WithColor(c Color) MixCode
- func (m MixCode) WithStyle(s Style) MixCode
- type Style
- func (s Style) Code() uint8
- 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 (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) String() string
- func (s Style) WithBackground(b Background) MixCode
- func (s Style) WithColor(c Color) MixCode
- func (s Style) WithStyle(s2 Style) MixCode
Constants ¶
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 ¶
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
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) Fprint ¶ added in v1.5.0
Fprint writes the colored string to io.Writer, with the given Color.
func (Color) Fprintf ¶ added in v1.5.0
Fprintf formats and writes the colored string to io.Writer, with the given Color.
func (Color) Fprintln ¶ added in v1.5.0
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) Println ¶
func (c Color) Println(a ...interface{})
Println prints the colored string and a newline, with the given Color.
func (Color) WithBackground ¶ added in v1.5.0
func (c Color) WithBackground(b Background) MixCode
WithBackground creates a MixCode with Color and Background.
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) Fprint ¶ added in v1.5.0
Fprint writes the styled and colored string to io.Writer, with the given MixCode.
func (MixCode) Fprintf ¶ added in v1.5.0
Fprintf formats and writes the styled and colored string to io.Writer, with the given MixCode.
func (MixCode) Fprintln ¶ added in v1.5.0
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
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
Sprint returns the styled and colored string, with the given MixCode.
func (MixCode) Sprintf ¶ added in v1.5.0
Sprintf formats and returns the styled and colored string, with the given MixCode.
func (MixCode) Sprintln ¶ added in v1.5.0
Sprintln returns the styled and colored string and a newline, with the given MixCode.
func (MixCode) WithBackground ¶ added in v1.5.0
func (m MixCode) WithBackground(b Background) MixCode
WithBackground creates a new MixCode with MixCode and Background.
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.
func (Style) Fprint ¶ added in v1.5.0
Fprint writes the styled string to io.Writer, with the given Style.
func (Style) Fprintf ¶ added in v1.5.0
Fprintf formats and writes the styled string to io.Writer, with the given Style.
func (Style) Fprintln ¶ added in v1.5.0
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
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) Sprintf ¶ added in v1.5.0
Sprintf formats and returns the styled string, with the given Style.
func (Style) Sprintln ¶ added in v1.5.0
Sprintln returns the styled string and a newline, with the given Style.
func (Style) WithBackground ¶ added in v1.5.0
func (s Style) WithBackground(b Background) MixCode
WithBackground creates a MixCode with Style and Background.