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/GoMudEngine/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: