There are generally two approaches for adding styling to text:
The first approach produces a styling that is 100% correct, regardless of the complexity of the text that is being output. This is the preferred approach for example for JSON, XML, or programming language text.
The second approach works well if the output has a simple, easy-to-parse format. It may produce wrong styling in some cases when the text format is more complex. This approach is often used for viewing log files.
GNU libtextstyle supports both approaches; it includes an example program for each of the two approaches.