How to use ANSI escape codes inside mvwprintw in ncurses?

假装没事ソ 提交于 2019-12-17 16:49:24

问题


Is there a way to use ANSI escape codes inside mvwprintw?

mvwprintw(window, 0, 0,"%c[%dmCOLORED_TEXT!\n", 0x1B, 32);//doesn't work

even though:

printf("%c[%dmCOLORED_TEXT\n", 0x1B, 32); //works

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.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/27464023/how-to-use-ansi-escape-codes-inside-mvwprintw-in-ncurses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!