[英]How to change IPython shell text literal color (Windows Powershell)
这是我为使文本更具可读性所做的工作。 感谢SO用户Theo和Christoph为我指出了正确的方向。
~\\.ipython
没有任何配置文件 ~
转换为C:\\Users\\<USER>\\
。 ipython profile create
PS C:\Somefolder> ipython profile create
[ProfileCreate] Generating default config file: 'C:\\Users\\<USER>\\.ipython\\profile_default\\ipython_config.py'
ipython_config.py
#c.TerminalInteractiveShell.highlighting_style_overrides = {}
进入
from pygments.token import Token
c.TerminalInteractiveShell.highlighting_style_overrides = {Token.String: '#ff0000'}
Token.Comment
Token.Error
Token.Escape
Token.Generic
Token.Keyword
Token.Literal
Token.Name
Token.Number
Token.Operator
Token.Other
Token.OutPrompt
Token.OutPromptNum
Token.Prompt
Token.PromptNum
Token.Punctuation
Token.String
Token.Text
Token.Token
在图中从左到右(以我自己的名字命名)
- Black #000000
- Middle blue #000080
- Green #008000
- Teal #008080
- Dark red #800000
- Dark blue #012456
- Light grey #eeedf0
- Grey #c0c0c0
- Dark grey #808080
- Bright blue #0000ff
- Bright light green #00ff00
- Bright light teal #00ffff
- Bright red #ff0000
- Pink #ff00ff
- Yellow #ffff00
- White #ffffff
我找到了一种设置单独颜色的方法。 在ipython_config.py
(如果您不知道如何到达那里,请参阅其他答案),您将找到带注释的条目c.TerminalInteractiveShell.highlighting_style_overrides
。 取消注释该条目,并根据您的喜好为String标记设置颜色:
## Override highlighting format for specific tokens
from pygments.token import Token
c.TerminalInteractiveShell.highlighting_style_overrides = {Token.String: '#009999'}
这使字符串再次可读!
解决了
在Win 10,Python 3.7和Python 3.8上-当将IPython与Powershell一起使用时,我遇到了问题-Windows将更改某些Python关键字(例如self)的颜色以匹配背景颜色,使其无法阅读。
这显然使使用IPython变得困难,因为关键字会在我键入时显示,但是当我完成单词时-它会更改颜色并被隐藏,尽管可编辑。
与解决此问题有关的解决方案是:
1-找到IPython配置(〜/ ipython / profile_default / ipython_config.py-或更改路径的任何存储ipython配置文件的位置)
2-确认我的机器支持TRUECOLOR(指令在ipython_config.py中)
3-取消注释此行。
*c.TerminalInteractiveShell.true_color = True*
4-重启IPython终端
使用ipython locate
在 .ipython 目录中找到您的ipython_config.py
配置文件。
如果您没有配置文件,请通过运行ipython profile create
创建一个。
在编辑器中打开ipython_config.py
文件并找到# c.TerminalInteractiveShell.highlighting_style = traitlets.Undefined
行。
删除注释并将taitlets.Undefined
位更改为c.TerminalInteractiveShell.highlighting_style = "fruity"
类的字符串。
保存并重新加载 ipython。
您可以通过在终端中运行pygmentize -L styles
来找到 highlighting_style 的所有选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.