A library for parsing ANSI encoded strings
Go ANSI Parser converts strings with ANSI escape codes into a slice of structs that represent styled text. Features:
- Can parse ANSI 16, 256 and TrueColor
- Supports all styles: Regular, Bold, Faint, Italic, Blinking, Inversed, Invisible, Underlined, Strikethrough
- Provides RGB, Hex, HSL, ANSI ID and Name for parsed colours
- Configurable colour map for customisation
- 100% Test Coverage
Installation
go get github.com/leaanthony/go-ansi-parser
Usage
var text, err = ansi.Parse("\u001b[1;31;40mHello World\033[0m")
// is the equivalent of...
var text = []*ansi.StyledText{
{
Label: "Hello World",
FgCol: &ansi.Col{
Id: 9,
Hex: "#ff0000",
Rgb: &ansi.Rgb{ R: 255, G: 0, B: 0 },
Hsl: &ansi.Hsl{ H: 0, S: 100, L: 50 },
Name: "Red",
},
BgCol: &ansi.Col{
Id: 0,
Hex: "#000000",
Rgb: &ansi.Rgb{0, 0, 0},
Hsl: &ansi.Hsl{0, 0, 0},
Name: "Black",
},
Style: 1,
},
}