在python间preTER提示添加颜色,不能正常换行 [英] Adding colors in python interpreter prompt, does not wrap properly

查看:109
本文介绍了在python间preTER提示添加颜色,不能正常换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个更加丰富多彩的Python提示符在终端,只是可读性。我目前有:

I would like to have a more colorful Python prompt in the terminal, just for readability. I currently have:

sys.ps1 = '\033[96m>>> \033[0m'
sys.ps2 = '\033[96m... \033[0m'

在我的 PYTHONSTARTUP 文件,它确实给它的颜色应有的作用。然而,过了线的任何文本不能正确换行。文去该行的末尾,而不是立即开始一个新的生产线,启动开始一个新的行之前覆盖所述第一行的开头。正如你可能想象,这其实是相当不可读。我怎样才能解决这个问题?

in my PYTHONSTARTUP file, which does give it colors as desired. However, any text over a line does not wrap properly. The text goes to the end of the line, and instead of immediately starting a new line, starts overwriting the beginning of the first line before starting a new line. As you might imagine, this is actually rather unreadable. How can I fix this behavior?

推荐答案

请尝试以下操作:

sys.ps1 = '\001\033[96m\002>>> \001\033[0m\002'
sys.ps2 = '\001\033[96m\002... \001\033[0m\002'

这样回答类似的问题解释了为什么 \\ 001 \\ 002 是必要的。

This answer to a similar question explains why the \001 and \002 are necessary.

这篇关于在python间preTER提示添加颜色,不能正常换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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