ANSI颜色C和ncurses的 [英] ANSI colors in C and 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:
-
创建(源WONTFIX)为ANSI转义codeS解析器。马特和屏幕实现这个:的https://lists.gnu .ORG /存档/ HTML /臭虫的ncurses / 2008-11 / msg00028.html
创建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屋!