syntax colors on ipython - bash

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.
This is the box where the config is not what I want
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?

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:
TerminalInteractiveShell.highlighting_style=<Union>
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.

Related

Neovim color schemes fail on Mac terminal

Switching from Vim (on VSCode) to nvim on my Mac, I'm trying to change some color schemes.
However, when I change with :colorscheme <color>, the changes in the window don't reflect what they should.
I originally found this error while trying to load a separate color scheme from github and it didn't work, then tried others and builtin ones and they all are wrong:
Choosing a scheme:
After chosen:
It seems all these default schemes are derivative of green highlight on white text on black background.
I figured it probably has something to do with Terminal preferences, but couldn't find any solutions.
Thanks!
So you are using the builtin terminal of macOS? If that is the case, probably because the builtin terminal does not support true colors. Get yourself a decent terminal emulator, like, kitty terminal, wezterm, iterm2.
Add the following to your config:
set termguicolors
Install a color scheme supporting true color, like gruvbox-material.
Switch to it colorsheme gruvbox-material. It should work.

In the Windows Subsystem for Linux (WSL / Bash on Ubuntu on Windows) how do I reset the colors to the default/original scheme?

I somehow messed up my color scheme in my Bash terminal on Windows and while I know how to customize the colors in Linux (edit your bashrc), I really don't want to have to manually do this and select all the colors myself. I liked the default color scheme and just want that back. Does anyone know how to do this?
.bashrc usually configuring the prompt and it's colors using PS1 (e.g. idan#pc-name:\mnt\c$). Where the default value on my WSL is:
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u#\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
With some mechanism to handle different kinds of terminals.
If you talk about the fonts and the colors of the background/foreground it is configured by the properties of the "Bash on Ubuntu on Windows" executable, right click on the ubuntu icon on the top left corner => Properties.

How to change laravel output color on the command line?

I am looking for a way to change the output color from laravels CLI tools. The output is really hard to read on a black terminal. I have tried grepping for the color yellow but i fear it might be a hex color. On the other hand it might be a composer setting any help is much appreciated.
Example Output:
Grep:
Extra Info:
OS: Ubuntu 12.04
Laravel: 4.1
In your case its not a Laravel thing - its a Ubuntu setting.
Try this:
Open the terminal
Go to edit-> profile preferences
Under the color tab, either check or uncheck the "use system colors" option (the opposite of what it is now). Alternatively you can also select another color scheme.

vim color not loaded or not working

I'm a fresh vim user, and I want to try new color themes.
I created a .vim dir which contains colors dir with themes and .vimrc file, and I created a symlink in my home dir, it is points to ./vim/.vimrc file.
Here is my .vimrc:
syntax enable
set t_Co=256
set synmaxcol=240
set background=dark
colorscheme twilight
let g:solarized_termcolors=256
This is the screenshot:
and that's what I want:
Whats wrong?
Note:
If I use the graphical macvim, it works, so something wrong with in my terminal
The let g:solarized_termcolors=256 is only useful if you use the solarized colorscheme. Since you want to use twilight, this line is useless and should be removed.
The twilight theme is GUI-only. Its colors are defined with hex values which are only understood by MacVim/GVim. It won't work in the terminal, no matter what you do. You can use twilight256 instead, which is designed for color terminals.
The vim themes, define a separate set of colors for the GUI (i.e. gvim) and the terminal (i.e. vim), hence you might end up seeing different colors in gvim vs vim. The reason behind that is the limited number of colors supported in the terminal compared to GUI.
CSApprox
But you could use a plugin like CSApprox, which will convert the colors in the GUI colorscheme to an equivalent one for terminal such that you see almost the similar set of colors. Most modern terminals (like Gnome Terminal, Console, OSX Terminal) that support 88 or 256 colors should work fine with this plugin.
The good thing about the CSApprox plugin is not separate configuration is necessary, and merely having this plugin in your .vim directory is good enough. And when you run the colorscheme command to choose a color scheme, this plugin automatically converts the colors for you as long as your terminal supports 88 or 256 colors.
And if you're running gvim or the terminal does not support 88/256 colors, this plugin just merely remains silent without doing any color conversions. And there is a mechanism to export the converted colors too I believe.
Alternative
Another similar plugin that I've heard is guicolorscheme which is similar to CSApprox, but you need to set the color scheme using the command :GuiColorScheme <color scheme name>.

Custom colorscheme not working on VIM

Here's what I did:
cp ~/.vim/colors/ir_black.vim /usr/share/vim/vim72/colors/
Then tried to open some code and :colorscheme ir_black
It changes a few colors but makes most of the text start to blink with the cursor.
It happens with almost all the other custom colorschemes as well. Does anyone have any ideas of what might be wrong?
I added t_Co=256 to my .vimrc file and it didn't seem to help.
PS: I'm on a Mac OS X.
Set your TERM to xterm-256color. Follow up on the iterm2 mailing list if that still doesn't work.
Edit : I found an exact duplicate of your question :here. It seems to be an issue with iTerm not supporting 256 colors by default.
The usual problem with color scheme and terminal is that terminal are often limited to 256 colors, and GUI color scheme are using 2^32 colors. So some of them are not correctly rendered in terminal.
There is a simple test to check: if you are lauching the GUI version is the color scheme rendered correctly ?
The possible solution are :
1. Convert your color scheme to 256 colors using the following plugin : CSApprox.vim
2. Choose a different color scheme. (Often on Vim.org color schemes compatible with Terminal have "256" in their name, like "wombat256" for example)
3. Use a GUI version like MacVim or GVim
If I remember correctly, the color sheme Zenburn is working nicely with both GUI and terminal version. It is rather dark with pastel colors.
Personal story : after spending ages to fiddle with color scheme to get something right for terminal, I switched to the GUI version. The GUI version with the icon bar hidden is not really different to terminal version anyway, as long as you are working locally
the default vim binary in /usr/bin/ will not work with any terminal. you need to have a version that supports gui - type "echo has('gui')" in vim command mode to check.
so your only option is to use a gui one (macvim etc.), or compile it with athena, gtk or x11 with macports, but i would advise against the latter, because it pulls down a shitload of dependencies.
i think it's better to use macvim for serious development that needs syntax highlighting, and use the 16 colour version in the terminal for quick edits.

Resources