// Colors #define KNRM "\x1B[0m" // default background & different foreground colors #define KRED "\x1B[49m\x1B[31m" #define KGRN "\x1B[49m\x1B[32m" #define KYEL "\x1B[49m\x1B[33m" #define KBLU "\x1B[49m\x1B[34m" #define KMAG "\x1B[49m\x1B[35m" #define KCYN "\x1B[49m\x1B[36m" #define KWHT "\x1B[49m\x1B[37m" // default background & different (light) foreground colors #define KLRED "\x1B[49m\x1B[91m" #define KLGRN "\x1B[49m\x1B[92m" #define KLYEL "\x1B[49m\x1B[93m" #define KLBLU "\x1B[49m\x1B[94m" #define KLMAG "\x1B[49m\x1B[95m" #define KLCYN "\x1B[49m\x1B[96m" #define KLWHT "\x1B[49m\x1B[97m" // diferent background colors & white foreground #define KBRED "\x1B[41m\x1B[37m" #define KBGRN "\x1B[42m\x1B[37m" #define KBYEL "\x1B[43m\x1B[37m" #define KBBLU "\x1B[44m\x1B[37m" #define KBMAG "\x1B[45m\x1B[37m" #define KBCYN "\x1B[46m\x1B[37m" #define KBWHT "\x1B[47m\x1B[30m"
时间: 2023-07-25 16:03:57 浏览: 161
这段代码是一个颜色定义的宏,用于在终端中显示不同的颜色。每个宏都定义了一个 ANSI 转义序列,用于在终端中设置对应的颜色。
这些宏可以分为几类:
1. 默认背景和不同前景颜色:
- `KRED`:红色
- `KGRN`:绿色
- `KYEL`:黄色
- `KBLU`:蓝色
- `KMAG`:洋红色
- `KCYN`:青色
- `KWHT`:白色
2. 默认背景和不同(浅色)前景颜色:
- `KLRED`:浅红色
- `KLGRN`:浅绿色
- `KLYEL`:浅黄色
- `KLBLU`:浅蓝色
- `KLMAG`:浅洋红色
- `KLCYN`:浅青色
- `KLWHT`:浅白色
3. 不同背景颜色和白色前景:
- `KBRED`:红底白字
- `KBGRN`:绿底白字
- `KBYEL`:黄底白字
- `KBBLU`:蓝底白字
- `KBMAG`:洋红底白字
- `KBCYN`:青底白字
- `KBWHT`:白底黑字
这些宏可以帮助你在终端中输出不同颜色的文本,例如使用 `printf` 函数:
```c
printf("%sHello, World!%s\n", KRED, KNRM);
```
这将以红色输出 "Hello, World!"。要恢复默认颜色,可以使用 `KNRM` 宏。
阅读全文