简体   繁体   English

Python颜色输出和分页输出

[英]Python color output and paging output

Python 2.4.x - I cannot install any non-standard modules. Python 2.4.x - 我无法安装任何非标准模块。 *nix environment. * nix环境。

So I've got an output that I have some color in using ansi coloring. 所以我有一个输出,我在使用ansi着色时有一些颜色。 Works great. 效果很好。 But the output is so long I needed to either pipe to less or use pydoc's page() 但输出很长我需要管道减少或使用pydoc的页面()

Once I do either - the color turns into 一旦我做了 - 颜色变成了

ESC[1;36m TEXT TO FOLLOW: ESC[1;37m

I saw over at Cucumber: pipe output without losing color that Adam says that lots of output that is piped lose it's color - but if sent to terminal it's just fine. 我在Cucumber看到:管道输出没有失去颜色 ,亚当说输出的很多输出都失去了它的颜色 - 但如果发送到终端它就好了。

Using pydoc's ttypager retains the color output - but doesn't provide a "less" type feature (scrolling back up). 使用pydoc的ttypager会保留颜色输出 - 但不提供“less”类型的功能(向上滚动)。

How do I get the best of both worlds? 我如何充分利用这两个世界? Color and Less type functionality? 颜色和更少类型的功能?

Thank you. 谢谢。

Use the -R flag with less . 使用-R标志less This will cause it to output ANSI color escape sequences as they are instead of changing them. 这将导致它输出ANSI颜色转义序列,而不是更改它们。 It appears to be supported on both my Debian box and my Mac OS X box, which is a good indication that -R is widely supported. 它似乎在我的Debian盒子和我的Mac OS X盒子上得到支持,这是-R得到广泛支持的一个很好的迹象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM