3 回答

TA貢獻1877條經(jīng)驗 獲得超6個贊
所有現(xiàn)代的終端仿真器都使用ANSI轉(zhuǎn)義碼來顯示顏色和其他內(nèi)容。
不用理會庫,代碼非常簡單。
更多信息在這里。
在C中的示例:
#include <stdio.h>
#define ANSI_COLOR_RED "\x1b[31m"
#define ANSI_COLOR_GREEN "\x1b[32m"
#define ANSI_COLOR_YELLOW "\x1b[33m"
#define ANSI_COLOR_BLUE "\x1b[34m"
#define ANSI_COLOR_MAGENTA "\x1b[35m"
#define ANSI_COLOR_CYAN "\x1b[36m"
#define ANSI_COLOR_RESET "\x1b[0m"
int main (int argc, char const *argv[]) {
printf(ANSI_COLOR_RED "This text is RED!" ANSI_COLOR_RESET "\n");
printf(ANSI_COLOR_GREEN "This text is GREEN!" ANSI_COLOR_RESET "\n");
printf(ANSI_COLOR_YELLOW "This text is YELLOW!" ANSI_COLOR_RESET "\n");
printf(ANSI_COLOR_BLUE "This text is BLUE!" ANSI_COLOR_RESET "\n");
printf(ANSI_COLOR_MAGENTA "This text is MAGENTA!" ANSI_COLOR_RESET "\n");
printf(ANSI_COLOR_CYAN "This text is CYAN!" ANSI_COLOR_RESET "\n");
return 0;
}

TA貢獻1802條經(jīng)驗 獲得超10個贊
處理顏色序列可能會變得混亂,并且不同的系統(tǒng)可能會使用不同的顏色序列指示器。
我建議您嘗試使用ncurses。除了顏色之外,ncurses還可以通過控制臺UI進行許多其他整潔的事情。
- 3 回答
- 0 關(guān)注
- 484 瀏覽
添加回答
舉報