Python 有等效的 Term::ANSIScreen 吗?
Perl 拥有出色的模块Term::ANSIScreen
,用于执行各种奇特的光标移动和终端颜色控制。 我想用 Python 重新实现当前 Perl 中的程序,但终端 ANSI 颜色是其功能的关键。 有人知道等效的吗?
Perl has the excellent module Term::ANSIScreen
for doing all sorts of fancy cursor movement and terminal color control. I'd like to reimplement a program that's currently in Perl in Python instead, but the terminal ANSI colors are key to its function. Is anyone aware of an equivalent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您只需要颜色,您可能想借用 pygments 的实现。 IMO 它比 ActiveState
http:// /dev.pocoo.org/hg/pygments-main/file/b2deea5b5030/pygments/console.py
If you only need colors You may want to borrow the implementation from pygments. IMO it's much cleaner than the one from ActiveState
http://dev.pocoo.org/hg/pygments-main/file/b2deea5b5030/pygments/console.py
还有 termcolor 和 termstyle 包。 如果 stdout 不是终端,后者能够禁用颜色输出。
另请参阅此问题。
There is also the termcolor and the termstyle packages. The latter is capable of disabling colour output if stdout is not a terminal.
See also this question.
这里有一个关于 ActiveState 的食谱,可以帮助您入门。 它涵盖颜色和位置。
[编辑:Jorge Vargas 上面提交的 pygments 代码是一个更好的方法。 ]
Here's a cookbook recipe on ActiveState to get you started. It covers colors and positioning.
[Edit: The pygments code submitted above by Jorge Vargas is a better approach. ]
虽然我自己没有使用过,但我相信curses库通常用于此目的:
http: //docs.python.org/library/curses.html
以及操作方法:
http://docs.python.org/howto/curses.html#curses-howto
不幸的是,这个模块似乎在 Windows 标准库中不可用。
该网站显然有一个 Windows 解决方案:
http://adamv.com/dev/python/curses/< /a>
While I haven't used it myself, I believe the curses library is commonly used for this:
http://docs.python.org/library/curses.html
And the How-to:
http://docs.python.org/howto/curses.html#curses-howto
Unfortunatly, this module doesn't appear to be available in the standard library for windows.
This site apparently has a windows solution:
http://adamv.com/dev/python/curses/