Ubuntu-16.04 [SOLVED]: syntax colors on ipython

Ubuntu-16.04 [SOLVED]: syntax colors on ipython

Home Forums Ubuntu 16.04 Ubuntu-16.04 [SOLVED]: syntax colors on ipython

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #36642



    This is bugged me for several days and what I’ve found so far on the internet do not satisfy me.

    I’ve installed ipython on two separate ubuntu boxes. The ipython prompt is different on each of the boxes.

    I’m reaching the boxes through ssh via a Windows bash emulator, Cmder

    This box where the config is closest to ok e.g it gives me syntax color when typing a string or else.

    enter image description here

    This is the box where the config is not what I want

    enter image description here

    Reading articles and questions, it seems that I need to add the line below in the file .bashrc in my linux account to be able to have syntax colors in ipython

    export LS_COLORS = "no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:ex =00;36"

    I did it but it still gives me the same grey outlook in my second box and worse, when I type a ls command in my linux box, I have this error

    ls: cannot analyse the value of the environment variable LS_COLORS

    Any ideas on what should I do to get color syntaxes for ipython?



    Accepted AnswerAnswer

    Recent versions of IPython use Prompt_toolkit, which provide colors via Pygments. YOu need to pass an option to IPython to select the “theme”, you’ll the following.

    If You issue ipython --help

    --colors=<CaselessStrEnum> (InteractiveShell.colors)
      Default: 'Neutral'
      Choices: ['Neutral', 'NoColor', 'LightBG', 'Linux']
      Set the color scheme (NoColor, Neutral, Linux, or LightBG).

    meaning you can either pass the --colors flag or set the c.InteractiveShell.colors=... in your config.

    You will also find the following option if you issue a In[1]: %config TerminalInteractiveShell:

        Current: 'legacy'
        The name or class of a Pygments style to use for syntax highlighting. To see
        available styles, run `pygmentize -L styles`.

    That controls the theme highlighting of IPython. (use --TerminalInteractiveShell.highlighting_style=... at the prompt , or set c.TerminalInteractiveShell.highlighting_style-... in a config file).

    Keep in ind the the escape control sequences used to show color may not be compatible with all terminal emulators, and that some part of IPython (in particular tracebacks) do not respect the themes (yes we know and we are planning to fix that at some point but it’s quite a bit of code to refactor).

    Keep in mind also that there are 2 types of colors with ANSI code. “True color” that is to say you tell the terminal emulator the R,G,B values of a character, and “short colors”. Where you tell the terminal emulator that the color of the character is one of 8 predefined colors. These 8 predefined colors depends on the terminal emulator itself and can sometime be changed from the terminal emulator preferences. See wikipedia for example of changes in colors.

    Source: https://stackoverflow.com/questions/47953896/syntax-colors-on-ipython
    Author: Matt
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.