如何在ncurses的mvwprintw内部使用ANSI转义代码? [英] How to use ANSI escape codes inside mvwprintw in ncurses?

查看:189
本文介绍了如何在ncurses的mvwprintw内部使用ANSI转义代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在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转义代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆