Documentation ¶
Index ¶
- Variables
- func Cleanse(input string, options ...ParseOption) (string, error)
- func HasEscapeCodes(input string) bool
- func Length(input string, options ...ParseOption) (int, error)
- func String(input []*StyledText) string
- func Truncate(input string, maxChars int, options ...ParseOption) (string, error)
- type Col
- type ColourMode
- type Hsl
- type ParseOption
- type Rgb
- type StyledText
- func (s *StyledText) Blinking() bool
- func (s *StyledText) Bold() bool
- func (s *StyledText) Bright() bool
- func (s *StyledText) Faint() bool
- func (s *StyledText) Inversed() bool
- func (s *StyledText) Invisible() bool
- func (s *StyledText) Italic() bool
- func (s *StyledText) Strikethrough() bool
- func (s *StyledText) String() string
- func (s *StyledText) Underlined() bool
- type TextStyle
Constants ¶
This section is empty.
Variables ¶
var ColourMap = map[string]map[string]*Col{ "Regular": { "30": Cols[0], "31": Cols[1], "32": Cols[2], "33": Cols[3], "34": Cols[4], "35": Cols[5], "36": Cols[6], "37": Cols[7], "90": Cols[8], "91": Cols[9], "92": Cols[10], "93": Cols[11], "94": Cols[12], "95": Cols[13], "96": Cols[14], "97": Cols[15], "100": Cols[8], "101": Cols[9], "102": Cols[10], "103": Cols[11], "104": Cols[12], "105": Cols[13], "106": Cols[14], "107": Cols[15], }, "Bold": { "30": Cols[8], "31": Cols[9], "32": Cols[10], "33": Cols[11], "34": Cols[12], "35": Cols[13], "36": Cols[14], "37": Cols[15], "90": Cols[8], "91": Cols[9], "92": Cols[10], "93": Cols[11], "94": Cols[12], "95": Cols[13], "96": Cols[14], "97": Cols[15], "100": Cols[8], "101": Cols[9], "102": Cols[10], "103": Cols[11], "104": Cols[12], "105": Cols[13], "106": Cols[14], "107": Cols[15], }, "Faint": { "30": Cols[0], "31": Cols[1], "32": Cols[2], "33": Cols[3], "34": Cols[4], "35": Cols[5], "36": Cols[6], "37": Cols[7], }, }
ColourMap maps ansi identifiers to a colour
var Cols = []*Col{}/* 256 elements not displayed */
Cols represents the default colour definitions used by the library. This may be overridden.
Functions ¶
func Cleanse ¶ added in v1.1.0
func Cleanse(input string, options ...ParseOption) (string, error)
Cleanse removes ANSI control symbols from the string.
func HasEscapeCodes ¶ added in v1.1.0
HasEscapeCodes tests that input has escape codes.
func Length ¶ added in v1.2.0
func Length(input string, options ...ParseOption) (int, error)
Length calculates count of user-perceived characters in ANSI string.
func String ¶ added in v1.1.0
func String(input []*StyledText) string
String builds an ANSI string for specified StyledText slice.
Types ¶
type Col ¶
type Col struct { Id int `json:"id"` Hex string `json:"hex"` Rgb Rgb `json:"rgb"` Hsl Hsl `json:"hsl"` Name string `json:"name"` }
Col represents a colour value. The Id is the ANSI colour ID.
type ColourMode ¶ added in v1.5.0
type ColourMode int
const ( Default ColourMode = 0 TwoFiveSix ColourMode = 1 TrueColour ColourMode = 2 )
type ParseOption ¶ added in v1.4.0
type ParseOption struct {
// contains filtered or unexported fields
}
ParseOption specifies parse option.
func WithDefaultBackgroundColor ¶ added in v1.4.0
func WithDefaultBackgroundColor(ansiColor string) ParseOption
WithDefaultBackgroundColor specifies default foreground code (ANSI 49). See ColourMap variable and foreground color codes 30-37.
func WithDefaultForegroundColor ¶ added in v1.4.0
func WithDefaultForegroundColor(ansiColor string) ParseOption
WithDefaultForegroundColor specifies default foreground code (ANSI 39). See ColourMap variable and foreground color codes 30-37.
func WithIgnoreInvalidCodes ¶ added in v1.4.0
func WithIgnoreInvalidCodes() ParseOption
WithIgnoreInvalidCodes disables returning an error on invalid ANSI code.
type StyledText ¶
type StyledText struct { Label string FgCol *Col BgCol *Col Style TextStyle ColourMode ColourMode // Offset is the offset into the input string where the StyledText begins Offset int // Len is the length in bytes of the substring of the input text that // contains the styled text Len int }
StyledText represents a single formatted string
func Parse ¶
func Parse(input string, options ...ParseOption) ([]*StyledText, error)
Parse will convert an ansi encoded string and return a slice of StyledText structs that represent the text. If parsing is unsuccessful, an error is returned.
func (*StyledText) Blinking ¶
func (s *StyledText) Blinking() bool
Blinking will return true if the text has a Blinking style
func (*StyledText) Bold ¶
func (s *StyledText) Bold() bool
Bold will return true if the text has a Bold style
func (*StyledText) Bright ¶ added in v1.5.0
func (s *StyledText) Bright() bool
Bright will return true if the text has a Bright style
func (*StyledText) Faint ¶
func (s *StyledText) Faint() bool
Faint will return true if the text has a Faint style
func (*StyledText) Inversed ¶
func (s *StyledText) Inversed() bool
Inversed will return true if the text has an Inversed style
func (*StyledText) Invisible ¶
func (s *StyledText) Invisible() bool
Invisible will return true if the text has an Invisible style
func (*StyledText) Italic ¶
func (s *StyledText) Italic() bool
Italic will return true if the text has an Italic style
func (*StyledText) Strikethrough ¶
func (s *StyledText) Strikethrough() bool
Strikethrough will return true if the text has a Strikethrough style
func (*StyledText) String ¶ added in v1.1.0
func (s *StyledText) String() string
func (*StyledText) Underlined ¶
func (s *StyledText) Underlined() bool
Underlined will return true if the text has an Underlined style
type TextStyle ¶
type TextStyle int
TextStyle is a type representing the ansi text styles
const ( // Bold Style Bold TextStyle = 1 << 0 // Faint Style Faint TextStyle = 1 << 1 // Italic Style Italic TextStyle = 1 << 2 // Blinking Style Blinking TextStyle = 1 << 3 // Inversed Style Inversed TextStyle = 1 << 4 // Invisible Style Invisible TextStyle = 1 << 5 // Underlined Style Underlined TextStyle = 1 << 6 // Strikethrough Style Strikethrough TextStyle = 1 << 7 // Bright Style Bright TextStyle = 1 << 8 )