Date : 2015.5.15 Author : Yang is QQ : 1209758756[email protected]
In the Linux environment for software development, debugging is often done, in order to make debugging information more clear and convenient, here to explain how to output with custom color font, such as can be customized output color red, green, blue, etc., and other printing information.
Let's start by explaining the application in shell scripts:
Output colored text in the shell using the echo command
Name
echo-Displays a line of text
Profile
echo [Options] ... [String] ...
Describe
Outputs a string to the standard output.
-N does not output line breaks
-E Open backslash ESC escape
-e Suppress backslash ESC escape (default)
--HELP Display Help
--version Display version
Note You must have the-e option for the output color.
And then say the point: ANSI control code is used in the output of color text.
-E to open escape in Echo
\e or \ 033来 output ESC symbol
Format color: \e[background color, foreground colour, highlight m
\033[background color, front color, highlight m
Restore defaults to \e[0m, and if you do not add this, then the output will remain the current color.
Where the background color can be replaced by the following numbers
First parameter:
0 transparent (using terminal color), 1 highlight 40 black, 41 red, 42 green, 43 yellow, 44 blue 45 Violet, 46 cyan
Green, 47 white (grey)
A second parameter:
The foreground color (that is, the colour of the text) can be replaced by the following numbers
30 Black 31 Red, 32 green, 33 yellow, 34 blue, 35 violet, 36 turquoise, 37 white (grey)
A third parameter:
Highlight is 1, not highlight is 0
The fourth parameter is m:
Note that the string is followed by M.
Instance:
1, output red font ABC, background color unchanged, the following three effects are the same
ECHO-E ' \033[0;31;1m ABC \033[0m '
ECHO-E "\e[1;31m ABC \e[0m"
ECHO-E "\e[0;31;1m ABC \e[0m"
2, Output yellow font ABC, red background color, the following three effects the same
ECHO-E ' \033[41;33;1m ABC \033[0m '
ECHO-E "\e[41;33m ABC \e[0m"
ECHO-E "\e[41;33;1m ABC \e[0m"
30 Black 31 Red, 32 green, 33 yellow, 34 blue, 35 violet, 36 turquoise, 37 white (grey)
Echo-e "\e[1;30m Skyapp exist \e[0m"//Black
Echo-e "\e[1;31m Skyapp exist \e[0m"//Red
Echo-e "\e[1;32m Skyapp exist \e[0m"//Green
Echo-e "\e[1;33m Skyapp exist \e[0m"//Yellow
Echo-e "\e[1;34m Skyapp exist \e[0m"//Blue
Echo-e "\e[1;35m Skyapp exist \e[0m"//Purple
Echo-e "\e[1;36m Skyapp exist \e[0m"//Turquoise
Echo-e "\e[1;37m Skyapp exist \e[0m"//White (grey)
Embedded in the method:
Echo-e "^[[1;30m Skyapp exist ^[[0m"//Black
Echo-e "^[[1;31m Skyapp exist ^[[0m"//Red
Echo-e "^[[1;32m Skyapp exist ^[[0m"//Green
Echo-e "^[[1;33m Skyapp exist ^[[0m"//Yellow
Echo-e "^[[1;34m Skyapp exist ^[[0m"//Blue
Echo-e "^[[1;35m Skyapp exist ^[[0m"//Purple
Echo-e "^[[1;36m Skyapp exist ^[[0m"//Turquoise
Echo-e "^[[1;37m Skyapp exist ^[[0m"//White (grey)
Note: The input method of the ^[is the CTRL + V key, and then the ESC key
The last use in C language:
[Email protected]]$ cat COLOR.C
/*********************************************************************************
* Copyright: (C) Yangzheng<[email protected]>
* All rights reserved.
*
* FILENAME:COLOR.C
* Description:this File
*
* version:1.0.0 (04/14/2015~)
* Author:yang Zheng<[email protected]>
* Changelog:1, Release initialversion on "04/14/2015 12:05:38 PM"
*
********************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#defineNONE "\033[m"
#defineRED "\033[0;32;31m"
#defineLIGHT_RED "\033[1;31m"
#defineGREEN "\033[0;32;32m"
#defineLIGHT_GREEN "\033[1;32m"
#defineBLUE "\033[0;32;34m"
#defineLIGHT_BLUE "\033[1;34m"
#defineDARY_GRAY "\033[1;30m"
#defineCYAN "\033[0;36m"
#defineLIGHT_CYAN "\033[1;36m"
#definePURPLE "\033[0;35m"
#defineLIGHT_PURPLE "\033[1;35m"
#defineBROWN "\033[0;33m"
#defineYELLOW "\033[1;33m"
#defineLIGHT_GRAY "\033[0;37m"
#defineWHITE "\033[1;37m"
Intmain ()
{
printf (CYAN "Current function is%s.\n", __function__);
printf (GREEN "Current line is%d.\n" NONE, __line__);
return exit_success;
}
Debug information output custom color font under Linux