本文介绍了用ncurses处理转义序列? printf是否处理转义序列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序从网络读取了一些文本数据,例如:Hello \033[1;34mworld\033[0m and bla bla bla!!!\n".当程序使用prinf输出此字符串时,单词"world"为蓝色.但是,当我将ncurses接口与wprintw或addch一起使用时,会看到带有转义序列的原始字符串.这是否意味着printf处理转义序列?用ncurses处理转义序列的最佳方法是什么?

My program read some text data from network, something like:Hello \033[1;34mworld\033[0m and bla bla bla!!!\n".When program output this string using prinf, the word "world" is blue. But when I'm using ncurses interface with wprintw or addch, I see the original string with escape sequences.Does it mean that printf handle escape sequences or not?What is the best way handle escape sequences with ncurses?

推荐答案

否,您的终端会处理转义序列.您看到的现象来自以下事实:ncurses的整个目的是跟踪预期的终端内容并能够对其进行重新粉刷,并且在执行此操作期间,它会剥离所有转义序列.它可能提供替代功能来解释并将其应用于终端应包含的内容,否则您将不得不自己完成这项工作...

No, your terminal handles the escape sequences. The phenomenon you're seeing comes from the fact that ncurses' whole purpose is to keep track of the intended terminal contents and be able to repaint it, and as part of doing this it strips any escape sequences. It might provide an alternative function to interpret them and apply them to its own image of what the terminal should contain, but otherwise you'll have to do this job yourself...

这篇关于用ncurses处理转义序列? printf是否处理转义序列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-14 15:30