An ANSI coloring application
Coloring an ANSI terminal application is handled by a variety of code before and after a section of text you want colored. This chapter will explore a basic coloring mechanism to color text red or plain. For a complete application, take a look at https://github.com/agtorre/gocolorize, which supports many more colors and text types and also implements the fmt.Formatter
interface for ease of printing.
Getting ready
Refer to the Getting ready section's steps in the Using command-line flags recipe.
How to do it...
These steps cover writing and running your application:
- From your terminal/console application, create and navigate to the
chapter2/ansicolor
directory. - Copy tests from https://github.com/agtorre/go-cookbook/tree/master/chapter2/ansicolor, or use this as an exercise to write some of your own code!
- Create a file called
color.go
with the following contents:
package ansicolor import "fmt" //Color of text type Color int const...