Curses for python. Convert ansi color codes from stdin to curses output

岁酱吖の 提交于 2020-01-14 16:36:51

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/11877851/curses-for-python-convert-ansi-color-codes-from-stdin-to-curses-output

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