ANSI颜色C和ncurses的 [英] ANSI colors in C and ncurses

查看:212
本文介绍了ANSI颜色C和ncurses的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我能做到 attron attroff 与我选择,但是,我想的颜色要知道是否有可能与ANSI颜色转义codeS ncurses的范围内做到这一点:

I know I can do the attron and attroff with the color I choose to, however, I would like to know if it's possible to do it with the ANSI colour escape codes within ncurses:

#include <stdio.h>
#include <ncurses.h>

int main()
{
   initscr();
   char *s2 = NULL;
   const char *s1 = "World";
   int n = 10; 

   // What would be a good way to colour %d?
   // seems it is not safe to us the ANSI color escape in here...
   s2 = malloc (snprintf (NULL, 0, "Hello %s \033[22;31m%d", s1, n) + 2); 
   sprintf (s2, "Hello %s \033[22;31m%d", s1, n); 
   printw("%s", s2);
   refresh();
   getch();
   endwin();

   return 0;
}

-lncurses

普通的的printf(\\ 033 [22; 31mHello,世界\\ n!); 在非ncurses的程序工作。

a regular printf("\033[22;31mHello, World!\n"); in a non-ncurses program works.

推荐答案

2010邮件列表线程讨论这个:的 https://lists.gnu.org/archive/html/bug-ncurses/2008-11/msg00026.html

2008 mailing list thread discussing this: https://lists.gnu.org/archive/html/bug-ncurses/2008-11/msg00026.html

提出的可能性分别为为:

The possibilities raised were to:

创建terminfo项:的https: //lists.gnu.org/archive/html/bug-ncurses/2008-11/msg00029.html

create a terminfo entry: https://lists.gnu.org/archive/html/bug-ncurses/2008-11/msg00029.html

这篇关于ANSI颜色C和ncurses的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆