Add color to your C program

Source: Internet
Author: User

The standard C console program can also customize the text output color to make the print information clearer, which is particularly useful in debugging. The method is simple:

From: http://www.diybl.com/course/3_program/c/c_js/20090303/157456.html

Start with an example.

Printf ("/033 [31 m ####----->/033 [32 m" "hello/n" "/033 [m ");

The color is divided into the background color and font color, 30 ~ 39 is used to set the font color, 40 ~ 49. Set the background as follows:

Font color of the background color <br/> 40: Black 30: Black <br/> 41: Red 31: Red <br/> 42: Green 32: Green <br/> 43: yellow 33: yellow <br/> 44: Blue 34: Blue <br/> 45: Purple 35: Purple <br/> 46: dark green 36: dark green <br/> 47: white 37: white

In addition, remember to restore the color to NONE after printing, otherwise the subsequent printing will change color.

 

You can also add some ANSI control codes. Color addition is only one of the following control codes:

/033 [0 m close all properties <br/>/033 [1 m set high brightness <br/>/033 [4 m underline <br/>/033 [5 m flashing <br/>/033 [7 m reverse display <br/>/033 [8 m blanking <br/>/033 [30 m --/033 [37 m set foreground view <br/ >/033 [40 m --/033 [47 m set background color <br/>/033 [nA cursor up n rows <br/>/033 [nB cursor down n rows <br/>/033 [right shift of nC cursor n rows <br/>/033 [left shift of nD cursor n rows <br/>/033 [y; xH set the cursor position <br/>/033 [2J clear screen <br/>/033 [K clear the content from the cursor to the end of the line <br/>/033 [s Save the cursor position <br/>/033 [u restore cursor position <br/>/033 [? 25l hide the cursor <br/>/033 [? 25 h show cursor

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.