我知道我可以做attron
和attroff
与我选择,但是,我想知道,如果有可能的ncurses内与ANSI颜色转义符来做到这一点的颜色:ANSI颜色C和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, World!\n");
在非ncurses的程序工作链接。
是的,我没有尝试,但没有奏效。我想知道,什么是做上述的好方法(我更新了我的示例代码) – DaNiro1 2010-12-07 05:43:49