How to make Emacs terminal colors the same as Emacs GUI colors?

EmacsUbuntuColors

Emacs Problem Overview


I program with Emacs on Ubuntu (Hardy Heron at the moment), and I like the default text coloration in the Emacs GUI. However, the default text coloration when Emacs is run in the terminal is different and garish.

How do I make the colors in the terminal match the colors in the GUI?

Emacs Solutions


Solution 1 - Emacs

You don't have to be stuck to your terminal's default 16 (or fewer) colours. Modern terminals will support 256 colours (which will get you pretty close to your GUI look).

Unfortunately, getting your terminal to support 256 colours is the tricky part, and varies from term to term. This page helped me out a lot (but it is out of date; I've definitely gotten 256 colours working in gnome-terminal and xfce4-terminal; but you may have to build them from source.)

Once you've got your terminal happily using 256 colours, the magic invocation is setting your terminal type to "xterm-256color" before you invoke emacs, e.g.:

env TERM=xterm-256color emacs -nw

Or, you can set TERM in your .bashrc file:

export TERM=xterm-256color

You can check if it's worked in emacs by doing M-x list-colors-display, which will show you either 16, or all 256 glorious colours.

If it works, then look at color-theme like someone else suggested.

(You'll probably get frustrated at some point; god knows I do every time I try to do something similar. But stick with it; it's worth it.)

Solution 2 - Emacs

I'm not sure if it is possible, as the GUI may have more capabilities than the terminal (yes, I've seen GUI terminals with only 16 colors very recently). It may depend on how the terminal is set. At any rate I would play with Color Theme.

Anyway, why are you using Emacs in both, the terminal and the GUI? Generally people find one or the other appealing and use only that one. If you are using Emacs remotely, maybe you want to run it locally and use Tramp to open files remotely, or as root.

Solution 3 - Emacs

A little late response but I had the problem with the black background showing up as grey. I fixed it by playing around with palette.

edit > Profile Preferences > Color > Palette

Solution 4 - Emacs

I was able to get pretty close with emacs 26.

I followed the Emacs FAQ to get 24-bit colors working: https://www.gnu.org/software/emacs/manual/html_mono/efaq.html#Colors-on-a-TTY

And then I changed the xterm-standard-colors variable:

(set 'xterm-standard-colors
  '(("black"          0 (  0   0   0))
    ("red"            1 (255   0   0))
    ("green"          2 (  0 255   0))
    ("yellow"         3 (255 255   0))
    ("blue"           4 (  0   0 255))
    ("magenta"        5 (255   0 255))
    ("cyan"           6 (  0 255 255))
    ("white"          7 (255 255 255))
    ("brightblack"    8 (127 127 127))
    ("brightred"      9 (255   0   0))
    ("brightgreen"   10 (  0 255   0))
    ("brightyellow"  11 (255 255   0))
    ("brightblue"    12 (92   92 255))
    ("brightmagenta" 13 (255   0 255))
    ("brightcyan"    14 (  0 255 255))
    ("brightwhite"   15 (255 255 255)))
  )

(I did not change the "bright*" colors because I don't use them, and they don't seem to be available in list-colors-display in X11 emacs, anyway)

With those two changes, colors look pretty much identical between X11 and terminal for me.

Solution 5 - Emacs

I don't think that is possible in such a general way. With the terminal you are usually bound to some pre-defined colors (with things like gnome-terminal you can adjust these colors -- but you are still stuck to a predefined, limited number of colors).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionZakView Question on Stackoverflow
Solution 1 - EmacsinsipidView Answer on Stackoverflow
Solution 2 - EmacspupenoView Answer on Stackoverflow
Solution 3 - EmacsAli ZandView Answer on Stackoverflow
Solution 4 - EmacsArseniy AlekseyevView Answer on Stackoverflow
Solution 5 - EmacsHD.View Answer on Stackoverflow