python的诅咒。将Ansi颜色代码从stdin转换为curses输出 [英] Curses for python. Convert ansi color codes from stdin to curses output

查看:82
本文介绍了python的诅咒。将Ansi颜色代码从stdin转换为curses输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两天前,我创建了 decrypt.py 。这是一个很有趣的程序。它从stdin读取并使用curses将乱码的内容打印到屏幕上。但是,当输入中存在特殊字符(如ansi颜色代码或制表符)时,它们将无法正确显示。



是否有一种很好的方式来映射这些字符

非常感谢您的帮助。

解决方案

这是一个相当不错的功能,所以我没有惊讶没有答案。考虑到3年的沉默,我认为您不会找到任何现成的代码来处理此问题。



我认为您能得到的最接近的是ansi到 colorama 中的win32映射。您必须编写一个类似的Regex解析器,然后使用它来转换为curses调用。


I created decrypt.py two days ago. It's quite a funny program. It reads from stdin and prints the contents garbled to the screen using curses. However, when there are special characters like ansi color codes or tabs present in the input, they don't get displayed properly.

Is there a good way to map these characters to the way curses handles tabs and colors on the terminal window?

Your help is much appreciated.

解决方案

This is a pretty niche function, so I'm not surprised there's been no answer. Given the 3 year silence, I don't think you'll find any ready-made code to handle this.

The closest I think you'll get is the ansi to win32 mapping in colorama. You would have to write a similar Regex parser and then use it to convert to curses calls instead.

这篇关于python的诅咒。将Ansi颜色代码从stdin转换为curses输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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