ansitags is a helper library that allows to you use common tags inside of text that result in ANSI escape code (color). Currently only one directional parsing is possible ( tagged strings ⮕ color escaped strings )
- ansitags.go Contains the code and structs for the basic parsing logic and flow of data, noteably
ansitags.Parse()
andansitags.ParseStreaming()
. - ansiproperties.go handles basic ansi properties/tag parsing and conversion into valid escape codes.
- tagmatcher.go basic helper struct to simplify finding ansi "tag" matches.
- ansitags_test.go Contains unit tests, benchmarks, etc
- testdata/ansitags_test.yaml Contains unit test data with input & expect output. The ANSI Control Sequence Introducer should be represented by a unicode escaped value -
\u001b
(Octal33
, Hexadecimal1b
, Decimal27
)
Import the module:
import "github.com/Volte6/ansitags"
Parse and print a string:
fmt.Println( ansitags.Parse("This is a <ansi fg='red' bg='blue'>white text on a blue background</ansi>") )
Result:
Note: You can switch between 256 color mode and 8 color mode (The default is 8):
ansitags.SetColorMode(ansitags.Color8)
ansitags.SetColorMode(ansitags.Color256)
- CSI sequence support such as cursor position
- Stripping out color codes / tags from strings
- Generating color-styled HTML from color codes / tags