\033[A1;A2;A3;...An m
假设封装4种颜色
#define RED(msg) "\033[0;1;31m"_msg_"\033[0m"
#define GREEN(msg)"\033[0;1;32m"_msg_"\033[0m"
#define YELLO(msg)"\033[0;1;33m"_msg_"\033[0m"
#define BlUE(msg)"\033[0;1;34m"_msg_"\033[0m"
_msg_
"hello world" 等价于"hello" ," " ,"world,在C语言中都一样
#color宏 #code代表字符串化
#define COLOR(msg,code) "\033[0;1;" #code "m" msg "\033[0m"
#define RED(msg) COLOR(msg,31)
#define GREEN(msg) COLOR(msg,32)
#define YELLO(msg) COLOR(msg,33)
#define BlUE(msg) COLOR(msg,34)
int main()
{
printf(RED("hello world"));
printf(GREEN("hello world"));
printf(YELLO("hello world"));
printf(BLUE("hello world"));
return 0;
}