(原+转)ubuntu终端输出彩色文字

转载请注明出处:

http://www.cnblogs.com/darkknightzh/p/6066697.html

参考网址:

http://www.tuicool.com/articles/jIbAjy

http://stackoverflow.com/questions/1718403/enable-bash-output-color-with-lua-script

 

C++

std::cout << "\033[31m some string: " << num << "\033[0m";

注意:貌似不恢复成默认颜色的话,后面的会一直是设置的颜色。

其中:

#define RESET   "\033[0m"
#define BLACK   "\033[30m"      /* Black */
#define RED     "\033[31m"      /* Red */
#define GREEN   "\033[32m"      /* Green */
#define YELLOW  "\033[33m"      /* Yellow */
#define BLUE    "\033[34m"      /* Blue */
#define MAGENTA "\033[35m"      /* Magenta */
#define CYAN    "\033[36m"      /* Cyan */
#define WHITE   "\033[37m"      /* White */
#define BOLDBLACK   "\033[1m\033[30m"      /* Bold Black */
#define BOLDRED     "\033[1m\033[31m"      /* Bold Red */
#define BOLDGREEN   "\033[1m\033[32m"      /* Bold Green */
#define BOLDYELLOW  "\033[1m\033[33m"      /* Bold Yellow */
#define BOLDBLUE    "\033[1m\033[34m"      /* Bold Blue */
#define BOLDMAGENTA "\033[1m\033[35m"      /* Bold Magenta */
#define BOLDCYAN    "\033[1m\033[36m"      /* Bold Cyan */
#define BOLDWHITE   "\033[1m\033[37m"      /* Bold White */

 

torch中:

print(string.format("\27[31m str: %s", strval))

注意:1. 其中\27为十进制的27,对应于8进制的033。

2. 貌似只对当前行有效。下一行还是默认颜色。

你可能感兴趣的:((原+转)ubuntu终端输出彩色文字)