我知道我可以使用我选择的颜色来执行attron
and attroff
,但是,我想知道是否可以使用 ncurses 中的 ANSI 颜色转义码来执行此操作:
#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 程序中的常规程序有效。