Documentation ¶
Overview ¶
go-ansisgr provides an SGR (Select Graphic Rendition, a part of ANSI Escape Sequence) parser.
Index ¶
- type Color
- type Iterator
- type Mode
- type Style
- func (s *Style) Background() (Color, bool)
- func (s *Style) Blink() bool
- func (s *Style) Bold() bool
- func (s *Style) Dim() bool
- func (s *Style) Foreground() (Color, bool)
- func (s *Style) Invisible() bool
- func (s *Style) Italic() bool
- func (s *Style) Reverse() bool
- func (s *Style) Strikethrough() bool
- func (s *Style) Underline() bool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Color ¶
type Color struct {
// contains filtered or unexported fields
}
Color represents color value specified by SGR.
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator is an iterator over a parsed string.
func NewIterator ¶
NewIterator returns a new Iterator.
Example ¶
package main import ( "fmt" "strings" ansisgr "github.com/ktr0731/go-ansisgr" ) func main() { in := "a\x1b[1;31;40mb\x1b[0;4;38;5;45;48;2;0;51;102mc" iter := ansisgr.NewIterator(in) var got []string for { r, style, ok := iter.Next() if !ok { break } var s []string s = append(s, fmt.Sprintf("rune: %c", r)) if color, ok := style.Foreground(); ok { switch color.Mode() { case ansisgr.Mode16, ansisgr.Mode256: s = append(s, fmt.Sprintf("foreground: %d", color.Value())) case ansisgr.ModeRGB: red, green, blue := color.RGB() s = append(s, fmt.Sprintf("foreground: %d (%d, %d, %d)", color.Value(), red, green, blue)) } } if color, ok := style.Background(); ok { switch color.Mode() { case ansisgr.Mode16, ansisgr.Mode256: s = append(s, fmt.Sprintf("background: %d", color.Value())) case ansisgr.ModeRGB: red, green, blue := color.RGB() s = append(s, fmt.Sprintf("background: 0x%06x (%d, %d, %d)", color.Value(), red, green, blue)) } } if style.Bold() { s = append(s, "bold") } got = append(got, strings.Join(s, ", ")) } fmt.Println(strings.Join(got, "\n")) }
Output: rune: a rune: b, foreground: 31, background: 40, bold rune: c, foreground: 45, background: 0x003366 (0, 51, 102)
type Style ¶
type Style struct {
// contains filtered or unexported fields
}
Style represents a set of attributes, foreground color, and background color.
func (*Style) Background ¶
Background returns the background color. the second return value indicates whether the color is valid or not.
func (*Style) Foreground ¶
Foreground returns the foreground color. the second return value indicates whether the color is valid or not.
func (*Style) Strikethrough ¶
Strikethrough indicates whether strikethrough is enabled.
Click to show internal directories.
Click to hide internal directories.