The go language is to print color characters similar to the Linux terminal output color characters, with a black background highlighting the green font as an example:
Fmt. Printf ("\ n%c[1;40;32m%s%c[0m\n\n", 0x1B, "Testprintcolor", 0x1B)
Where 0x1b is the marker, [start defining the color, 1 for highlighting, 40 for the black background, 32 for the green foreground, and 0 for restoring the default color. The display effect is:
The following code iterates through all the display effects.
Package Mainimport ( "FMT") func main () { fmt. Println ("") //foreground background color //--------------------------------------- // black // 41 Red///green/// yellow // Blue // Magenta //- Blue //Panax Notoginseng White//// code meaning //------------------------- // 0 terminal default settings // 1 highlighting // 4 using underscore // 5 blinking // 7 Anti-white display //8 invisible for b: =; b <=; b++ {//Background color = 40-47 for f: =; F <= 37 ; f++ {//Foreground color = 30-37 for d: = range []int{0, 1, 4, 5, 7, 8} {//display mode = 0,1,4,5,7,8 fmt. Printf ("%c[%d;%d;%dm%s (f=%d,b=%d,d=%d)%c[0m", 0x1B, D, B, F, "", F, B, D, 0x1B) } fmt. Println ("") } fmt. Println ("") }}
The display effect is:
Notes Go language output color characters in Linux environment