我知道我可以做的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 …
我正在用 Python 编写一个 curses 程序。我是诅咒的初学者,但我已经使用终端控制序列进行彩色输出。
现在有一些代码片段要打印在窗口内,我希望它们被语法突出显示,最好使用像 pygments 这样的库来完成,它输出带有控制序列的突出显示代码。
最初我将 pygments 输出直接提供给window.addstr(),但结果是控制序列被转义并且整个突出显示的字符串打印在屏幕上(就像这样:https : //too-young.me/web/repos/curses-突出显示.png)。我怎样才能直接用诅咒来显示它,就像cat?