Pleasant Goat Series C language Character interface color output (printf)

Source: Internet
Author: User
Tags clear screen set background usleep

Blog: Http://blog.csdn.net/muyang_ren

1. header File Print.h

/*printf output with color font [http://hi.baidu.com/lukunnr/blog/item/cd3b4e5429d098c8b745ae86.html]printf output color and ANSI control code (highlighted, underlined, Flashing, cursor position, clear screen, etc.) to the output of printf and some special effects such as color, can make the printing information more vivid, in the debug time is particularly useful. Color: */#define NONE "\033[m" #define RED "\033[0;32;31m" #define light_red "\033[1;31m" #define GREEN "\033[0;32;32m" # Define Light_green "\033[1;32m" #define BLUE "\033[0;32;34m" #define Light_blue "\033[1;34m" #define Dary_gray "\033[1; 30m "#define CYAN" \033[0;36m "#define Light_cyan" \033[1;36m "#define PURPLE" \033[0;35m "#define Light_purple" \033[1; 35m "#define BROWN" \033[0;33m "#define YELLOW" \033[1;33m "#define Light_gray" \033[0;37m "#define WHITE" \033[1;37m "/*  For example: printf ("\033[31m #----->> \033[32m" "" hello\n "" \033[m ") int main () {printf (CYAN" Current function is%s "GREEN "File line was%d\n" none,__function__, __line__); fprintf (stderr, RED "current FUNCTION was%s" BLUE "file line is%d\n "none,__function__, __line__); return 0;} *//* color is divided into background and font color, 30~39 used to set the font color, 40~49 setting background: Background color font Color 40: Black 30: Black 41: Red 31: Red 42: Green 32: Green 43: Yellow 33: Yellow 44: Blue 34: Blue 45: Violet 35: Violet 46: Dark green 36: Dark green 47: White 37: White Remember to restore the color to none after printing, otherwise the subsequent printing will follow the color change. *///Additionally, you can add some ANSI control codes. Add color is just one of the following control codes: #define CLOSE "\033[0m"//Turn off all properties # define High "\033[1m"//Set H # define line "\033[4m"//Underline # define Light "\033[5m"//Blinking # F1 "\033[7m"//Inverse # define F2 "\033[8m"//Blanking # define FORE1 "\033[30m" #define FORE2 "\033[31m" #define Fore3 "\033[32m" #define FORE4 "\033[33m" #define FORE5 "\033[34m" #define FORE6 "\033[35m" #define FORE7 "\033[36m" #define Fore8 "\033[37m" #define BACK1 "\033[0;32;40m" #define BACK2 "\033[0;32;41m" #define BACK3 "\033[42m" #define BACK4 "\033[ 43m "#define BACK5" \033[44m "#define BACK6" \033[45m "#define BACK7" \033[46m "#define BACK8" \033[47m "//\033[30m--\033[  37m set foreground//\033[40m--\033[47m Set Background color # define UP "\033[1A"//cursor up N line # define down "\033[1b"//Cursor down n line # define right "\033[1c" Cursor right shift n Line # define left "\033[3d"//cursor shift n Line # # LEFT1 "\033[1D"//cursor left n line # define F3 "\033[0;0h"//Set cursor position # define CLEAR "\033 [2J]//Clear Screen # # clean "\033[k"//clear the content from the cursor to the end of the line #deFine F4 "\033[s"//Save cursor position # define F5 "\033[u"//restore cursor position # define F6 "\033[?25l"//Hide cursor # define F7 "\033[?25h"//Display cursor 

2. Testing

TEST.c

#include <stdio.h> #include "print.h" int main (void) {#if 1 printf (RED "***********************\n" NONE); printf ( Light_red "***********************\n" NONE); printf (GREEN "***********************\n" NONE); printf (light_green "***********************\n" NONE); printf (BLUE "***********************\n" NONE); printf (light_blue "***********************\n" NONE); printf (dary_gray "***********************\n" NONE); printf (CYAN "***********************\n" NONE); printf (Light_cyan "***********************\n" NONE); printf (PURPLE "***********************\n" NONE); printf (light_purple "***********************\n" NONE); printf (BROWN "***********************\n" NONE); printf (YELLOW "***********************\n" NONE); printf (light_gray "***********************\n" NONE); printf (white "***********************\n" NONE); printf (High "***********************\n" NONE); printf (line "***********************\n" NONE); printf (light "***********************\n" NONE); printf (F1 "***********************\n" NONE); printf (F2 "*******************\ n "None); #endif # if 0 printf (fore1" ***********************\n "none); printf (fore2 "***********************\n" NONE); printf (fore3 "***********************\n" NONE); printf (fore4 "***********************\n" NONE); printf (fore5 "***********************\n" NONE); printf (fore6 "***********************\n" NONE); printf (fore7 "***********************\n" NONE); printf (Fore8 "***********************\n" NONE); printf (back1 "***********************\n"); printf (back2 "***********************\n"); printf (back3 "***********************\n"); printf (back4 "***********************\n"); printf (back5 "***********************\n"); printf (back6 "***********************\n"); printf (back7 "***********************\n");      printf (back8 "***********************\n" NONE); #endif # if 0 int i1,i2,i3,i4,i,j,n = 6;  for (i = 11,j = 0; j < n; I--, j + +) {for (I1 = 0;i1 <= i-2*j;i1++) {printf (Right RED "#" NONE);  Fflush (stdout);    Usleep (100000);  } for (I2=0;i2 <= i-2*j-1;i2++) {printf (LEFT1-Down BLUE "#" NONE); FflUsh (stdout);    Usleep (100000);  } for (i3 = 0;i3 <= i-2*j-1;i3++) {printf (left GREEN "#" NONE);  Fflush (stdout);    Usleep (100000);  } for (i4=0; i4 < i-2*j;i4++) {printf (LEFT1 up YELLOW "#" NONE);  Fflush (stdout);    Usleep (100000);      } printf (down-right); } #endif # if 0/**************************************************/printf (up "####################\n"); printf ("***********************\n"); printf (right "***********************\n"); printf (left "***********************\n"); printf (F3 "***********************\n"); printf (CLEAR "***********************\n"); printf (clean "***********************\n"); printf (F4 "***********************\n"); printf (F5 "***********************\n"); printf (F6 "***********************\n");       printf (F7 "***********************\n");      /*****************************************************/#endif # if 0 int i;      for (i = 0; i < 8; i++) printf (LEFT1 down); printf (left); #endif return 0;}


Pleasant Goat Series C language Character interface color output (printf)

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.