) Output Color characters in Linux

Source: Internet
Author: User

In ANSI compatible terminals (such as xterm, rxvt, and konsole), texts can be displayed in color, not just in black and white. HoweverProgramCan I output color characters? Of course, the answer is yes. The following statement outputs the highlighted black background green text.
Printf ("\ 033 [1; 40; 32 M % s \ 033 [0 m", "hello, nsfocus \ n ");

\ 033 declares the start of the escape sequence, and then [begins to define the color. The following 1 defines the highlighted characters. Then there is the background color, where 40 represents the black background. Next is the foreground color, which is 32, indicating green. We use \ 033 [0 m to close the escape sequence, and \ 033 [0 m is the default terminal color.

Through the above introduction, we will know how to output color characters. So I will not talk about it any more. The following are some definitions of color character colors:


Foreground background color

------------------------------------- 30 40 black 31 41 yellow 32 42 yellow 33 43 yellow 34 44 yellow 35 45 purple yellow 36 46 green yellow 37 47 whiteCodeMeaning ------------------------- 0 terminal default settings 1 Highlight 4 Use underline 5 Flash 7 reverse white display 8 invisible
 
 
 
The STD: cout of PS: C ++ can also be used.

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.