用ncurses处理转义序列? printf是否处理转义序列?

编程入门 行业动态 更新时间:2024-10-13 12:25:03
本文介绍了用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是否处理转义序列?

本文发布于:2023-10-08 15:03:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1472975.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:序列   ncurses   printf

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!