Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change IPython shell text literal color (Windows Powershell)

Problem definition

I use IPython on Windows Powershell. For some reason the color of string literals is unreadably dark red:

Ipython in powershell

For comparison, here is how it looks on VSCode, using powershell "shell" and Ipython:

Ipython in powershell in VSCode

Question

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.

like image 200
np8 Avatar asked Jan 27 '23 12:01

np8


1 Answers

Here is what I did to make the text more readable. Thanks for SO users Theo and Christoph for pointing me to right direction.

1. Checked that I do not have any configuration files in ~\.ipython

  • On windows ~ translated into C:\Users\<USER>\.

2. Ran ipython profile create

  • The output was
PS C:\Somefolder> ipython profile create
[ProfileCreate] Generating default config file: 'C:\\Users\\<USER>\\.ipython\\profile_default\\ipython_config.py'

3. Edited the ipython_config.py

  • Edited the following line:
#c.TerminalInteractiveShell.highlighting_style_overrides = {}

into

from pygments.token import Token
c.TerminalInteractiveShell.highlighting_style_overrides = {Token.String: '#ff0000'}

Results

enter image description here

Other tokens

  • From pygments.token
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

Available colors in PowerShell:

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

Powershell options (colors)

like image 80
np8 Avatar answered Jan 29 '23 23:01

np8