1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<curses.h> 4 5 #define pri(fmt, ...) printf("["__FILE__"] <%s>_<%d> " ,__FUNCTION__,__LINE__ ); 6 printf(fmt, ##__VA_ARGS__); 7 8 int main() 9 { 10 pri(" ok "); 11 initscr(); 12 cbreak(); 13 noecho(); 14 15 if (has_colors() == FALSE) 16 { 17 pri(" ok "); 18 endwin(); 19 pri("Your terminal does not support color "); 20 exit(1); 21 } 22 endwin(); 23 pri("Your terminal support color ! "); 24 return 0; 25 }
运行后显示
[zlll@zlll-pc ballgame]$ ./a.out [ballgame8.C] <main>_<10> ok [ballgame8.C] <main>_<23> Your terminal support color ! [zlll@zlll-pc ballgame]$
则说明终端支持显示颜色
参考博客: https://blog.csdn.net/weixin_38184741/article/details/86165307?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522161012377516780269857944%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=161012377516780269857944&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_v1~rank_blog_v1-4-86165307.pc_v1_rank_blog_v1&utm_term=ncurses&spm=1018.2226.3001.4450