Skip to content

Simple tag structure for color coding strings and a function to parse it into ANSI escape codes

Notifications You must be signed in to change notification settings

GoMudEngine/ansitags

Repository files navigation

ansitags

Overview

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 stringscolor escaped strings )

  • ansitags.go Contains the code and structs for the basic parsing logic and flow of data, noteably ansitags.Parse() and ansitags.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 (Octal 33, Hexadecimal 1b, Decimal 27)

Quick Start

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:

alt text

About

Simple tag structure for color coding strings and a function to parse it into ANSI escape codes

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •