Linux Ncurses库:判断终端是否可以显示颜色

 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 \n");
11     initscr();
12     cbreak();
13     noecho();
14 
15     if (has_colors() == FALSE)
16         {
17             pri(" ok \n");
18             endwin();
19             pri("Your terminal does not support color\n");
20             exit(1);
21         }
22     endwin();    
23     pri("Your terminal support color !\n");
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

posted @ 2021-01-09 01:00  楸壳  阅读(136)  评论(0编辑  收藏  举报