Notes Go language output color characters in Linux environment

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.