Reputation: 33810
I use IPython on Windows Powershell. For some reason the color of string literals is unreadably dark red:
For comparison, here is how it looks on VSCode, using powershell "shell" and Ipython:
IPython certainly uses some commands to tell the shell the color to be used. How can I modify the string literal color to be lighter red? I would like this to be computer-wide (or at least user-wide) setting.
Upvotes: 7
Views: 1687
Reputation: 487
Locate your ipython_config.py
profile in the .ipython directory using ipython locate
.
If you don't have a profile, create one by running ipython profile create
.
Open the ipython_config.py
file in an editor and find the # c.TerminalInteractiveShell.highlighting_style = traitlets.Undefined
line.
Remove the comment and change the taitlets.Undefined
bit into a string like c.TerminalInteractiveShell.highlighting_style = "fruity"
.
Save and reload ipython.
You can find all the options for highlighting_style by running pygmentize -L styles
in a terminal.
Upvotes: 0
Reputation: 71
SOLVED
On Win 10, Python 3.7 and Python 3.8 - I faced issues when using IPython with Powershell - where Windows would change the color of certain Python keywords (e.g. self) to match the background color making it impossible to read.
This obviously made using IPython difficult because keywords would show as I typed, but when I finished the word - it would change color and be hidden, although editable.
The fix, related to solutions to this problem, was to:
1- find the IPython configuration (~/ipython/profile_default/ipython_config.py - or wherever you are storing your ipython profile if you have changed path)
2- confirm my machine supports TRUECOLOR (instructions are in ipython_config.py)
3 - uncomment this line.
*c.TerminalInteractiveShell.true_color = True*
4- restart IPython terminal
Upvotes: 0
Reputation: 33810
Here is what I did to make the text more readable. Thanks for SO users Theo and Christoph for pointing me to right direction.
~\.ipython
~
translated into 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 = {}
into
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
From left to right in the figure (with my own naming)
- 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
Upvotes: 7
Reputation: 5612
I have found a way to set individual colors. In ipython_config.py
(see other answer if you don't know how to get there), you will find a commented entry c.TerminalInteractiveShell.highlighting_style_overrides
.
Uncomment that entry and set a color for the String token to your liking:
## Override highlighting format for specific tokens
from pygments.token import Token
c.TerminalInteractiveShell.highlighting_style_overrides = {Token.String: '#009999'}
This makes strings readable again!
Upvotes: 3