Set the color of printf output font in terminal

Source: Internet
Author: User

The color of the terminal character is controlled by the escape sequence, which is the system display function in the text mode, regardless of the specific language.
The escape sequence starts with the ESC and can do the same with \033 (the ASCII code for ESC is in decimal notation is 27, = 33 in octal).

A) format is:

\033[display mode; foreground color; background colour m

1) display mode: 0 (default), 1 (highlighted), 22 (not bold), 4 (underscore), 24 (non-underlined), 5 (blinking), 25 (non-flashing), 7 (inverted), 27 (non-inverting)
2) Foreground: 30 (Black), 31 (red), 32 (green), 33 (yellow), 34 (blue), 35 (magenta), 36 (cyan), 37 (white)
3) Background color: 40 (Black), 41 (red), 42 (green), 43 (yellow), 44 (blue), 45 (magenta), 46 (cyan), 47 (white)

II) Examples:

1) Default color: \033[0m
2) Green: \033[1;32;40m
3) Red: \033[1;31;40m

4) printf ("\033[1;31;40m output red character \033[0m")

Set the color of printf output font in terminal

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.