我知道我可以做的attron,并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;
}
Run Code Online (Sandbox Code Playgroud)
与...联系 -lncurses …