Python 有等效的 Term::ANSIScreen 吗?

发布于 2024-07-13 09:30:07 字数 130 浏览 7 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

溺深海 2024-07-20 09:30:08

如果您只需要颜色,您可能想借用 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

半世晨晓 2024-07-20 09:30:08

还有 termcolortermstyle 包。 如果 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.

若水微香 2024-07-20 09:30:08

这里有一个关于 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. ]

万水千山粽是情ミ 2024-07-20 09:30:08

虽然我自己没有使用过,但我相信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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文