July 2019
Intermediate to advanced
458 pages
12h 12m
English
The pseudo-terminal can be improved by providing colored output. We have already seen that, in Unix, there are escape sequences that can change the background and foreground color. Let's start by defining a custom type:
type color intfunc (c color) Start(w io.Writer) { fmt.Fprintf(w, "\x1b[%dm", c)}func (c color) End(w io.Writer) { fmt.Fprintf(w, "\x1b[%dm", Reset)}func (c color) Sprintf(w io.Writer, format string, args ...interface{}) { c.Start(w) fmt.Fprintf(w, format, args...) c.End(w)}// List of colorsconst ( Reset color = 0 Red color = 31 Green color = 32 Yellow color = 33 Blue color = 34 Magenta color = 35 Cyan color = 36 White color = 37)
This new type can be used to enhance commands with ...
Read now
Unlock full access