问题描述
是否可以在mvwprintw
中使用ANSI转义码?
Is there a way to use ANSI escape codes inside mvwprintw
?
mvwprintw(window, 0, 0,"%c[%dmCOLORED_TEXT!\n", 0x1B, 32);//doesn't work
尽管:
printf("%c[%dmCOLORED_TEXT\n", 0x1B, 32); //works
这将适用于不方便使用wattron
/wattroff
的情况;例如,当从输出此类转义码的进程的stdout重定向输出时.
This would be for cases where using wattron
/wattroff
is not convenient; for example, when redirecting output from stdout of a process that outputs such escape codes.
推荐答案
否.进行该工作的唯一方法是自己解析该字符串,将转义码重新转换为适当的curses命令,然后与您的输出一起发出.
No. The only way to make that work would be to parse the string yourself, turning escape codes back into the appropriate curses commands, to issue along with your output.
您应该意识到的一件事是,尽管这些代码得到了广泛的实施,但却不是通用的. curses的主要目的之一是将其标准命令转换为一系列特定于终端的控制代码.因此,传递可能与当前终端类型相对应或不与之对应的代码并不完全适合curses模型.从根本上说,这些代码将以一种无法诅咒的方式更改终端状态,从而使其窗口结构的内容不再与屏幕上的内容匹配.
One thing you should realize is that those codes, although widely implemented, are not universal. One of the major purposes of curses is to translate its standard commands into series of terminal-specific control codes. So, passing through codes that may or may not correspond to the current terminal type doesn't really fit the curses model. Even more fundamentally, the codes would change the terminal state in a way that curses wouldn't be able to keep track of, so that the contents of its window structures no longer matched what was on screen.
这篇关于如何在ncurses的mvwprintw内部使用ANSI转义代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!