3

OS: Linux 4.19.0-16-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64 GNU/Linux
Emacs: GNU Emacs 28.0.50, with a solarized theme from here
Terminal emulator: terminator 1.91, with a solarized (dark) palette


The displays below were done by running the following bash script within a *shell* buffer (i.e. a buffer started with M-x shell):

echo -e '\e[30m██\e[31m██\e[32m██\e[33m██\e[34m██\e[35m██\e[36m██\e[37m██\e[0m'

"No-window"/"non-GUI" (-nw) Emacs process, running on a terminator 1.91 terminal emulator: enter image description here

"GUI Emacs" process:

enter image description here

How can I make ANSI colors in the GUI Emacs environment look like those in the "non-GUI" environment?

NB: I do not want to modify my terminal emulator in any way. I am happy with it. I want to modify GUI Emacs so that it produces the same behavior as my terminal emulator does.


For what it's worth, below are the first 8 colors in the output for (list-colors-display) running on "non-GUI" Emacs, which correspond to the colors I get from the ANSI color test shown above:

enter image description here

The colors with the same names (as reported by (list-colors-display) in "GUI-Emacs" are shown below; again, they match the colors from the ANSI colors test shown earlier:

enter image description here

In light of this, it occurs to me that maybe a way to achieve what I want is to redefine the colors black, red, ..., white? How would I do this?

Is there a "better" ("higher-level", more robust, etc.) way to solve this problem?


EDIT: The accepted answer in #000000 and true black in terminal Emacs colors shows that its OP's issue was due to his gnome-terminal configuration. My question, on the other hand, has nothing to do with gnome-terminal, or with terminal emulators in general. It's about GUI Emacs. The one other answer to https://emacs.stackexchange.com proposes to modify the default font. This will not solve my problem. Changing the default font would affect at most one foreground color. I have a problem with 8 colors. Also, the text that exhibits these various colors often have the same face (e.g. comint-highlight-prompt).

EDIT:

I changed the code for the ANSI color test to this:

echo -e '\e[30m██\e[31m██\e[32m██\e[33m██\e[34m██\e[35m██\e[36m██\e[37m██\e[0m'
echo -e '\e[30mXX\e[31mXX\e[32mXX\e[33mXX\e[34mXX\e[35mXX\e[36mXX\e[37mXX\e[0m'

Now, the output (on "GUI Emacs") is this:

enter image description here

The key point is this: According to describe-face, all those X's have the default face. These means that no solution based on modifying faces will solve this problem.


EDIT: First I ran this:

;; just to get a response...
(setq ansi-color-names-vector
  ["red3" "red3" "red3" "red3" "red3" "red3" "red3" "red3"])

(ansi-color-make-color-map) ;; is this necessary???

Then I started a fresh *shell* buffer (M-x shell), and ran the ANSI color test shown above, namely:

echo -e '\e[30m██\e[31m██\e[32m██\e[33m██\e[34m██\e[35m██\e[36m██\e[37m██\e[0m'
echo -e '\e[30mXX\e[31mXX\e[32mXX\e[33mXX\e[34mXX\e[35mXX\e[36mXX\e[37mXX\e[0m'

I got the same results I got earlier. In particular, the 8 colors were different, even though all 8 entries in ansi-color-names-vector are the same.


kjo
  • 3,145
  • 14
  • 42
  • 1
    Does this answer your question? [#000000 and true black in terminal Emacs colors](https://emacs.stackexchange.com/questions/36219/000000-and-true-black-in-terminal-emacs-colors) – Tyler Aug 05 '21 at 17:44
  • @Tyler I don't see any connection. – Gilles 'SO- stop being evil' Aug 05 '21 at 20:06
  • 1
    I think you need to customize `ansi-color-names-vector`. – Gilles 'SO- stop being evil' Aug 05 '21 at 20:07
  • See also `ansi-color-faces-vector` – lawlist Aug 05 '21 at 20:19
  • @Gilles'SO-stopbeingevil' the connection is that colors in terminal emacs and gui emacs don't necessarily match; it depends on the color profile of the terminal. I'm not sure how to set the terminator color profile, but for gnome-terminal there's an option in the tool bar that solved an issue very similar to this (i.e., colors in terminal differed from those in gui) – Tyler Aug 05 '21 at 20:37
  • @Tyler: I ***don't*** want to change what my terminal emulator is doing. I want to change what GUI emacs is doing. – kjo Aug 05 '21 at 20:40
  • @Gilles'SO-stopbeingevil': No matter how I change `ansi-color-names-vector` I see no difference. I even changed it so that all its elements are `"red1"`, and then ran `(ansi-color-make-color-map)`, but I still get the same colors when I run the 8-color test shown above. Do I need to do anything else to get the new definition of `ansi-color-names-vector` to have an effect? – kjo Aug 05 '21 at 20:49
  • 1
    Sorry, I thought you were trying to get the colors the same in GUI and terminal, when you really wanted to change the GUI to match customizations you have applied to the terminal. – Tyler Aug 05 '21 at 21:03
  • Changing ansi-color-names-vector doesn't change list-colors-display for me, but it does change the output in shell-mode. Did you try re-running your echo command after changing ansi-color-names-vector? – Tyler Aug 05 '21 at 21:05
  • @Tyler: I did, but maybe I did something wrong? I'll edit my post to spell out exactly what I did. It'll be a few minutes. – kjo Aug 05 '21 at 21:08
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/128274/discussion-between-tyler-and-kjo). – Tyler Aug 05 '21 at 21:12

1 Answers1

2

After some exploring, we determined that @Gilles suggestion of modifying ansi-color-names-vector was the correct approach. It can't be set with a regular setq, it needs to be updated through the Customize interface (i.e., M-x customize-variable ansi-color-names-vector. Changing the value won't change existing text in the shell terminal, but new text added after the update will take the new colors.

If you do want to set it from code, you need to do this:

(setq ansi-color-names-vector
      ["red3" "red3" "red3" "red3" "red3" "red3" "red3" "red3"])

(ansi-color-map-update 'ansi-color-names-vector ansi-color-names-vector)
Tyler
  • 21,719
  • 1
  • 52
  • 92
  • Thank you! BTW, how did you figure out that the call to `ansi-color-map-update` was necessary? (I had been using `ansi-color-make-color-map` instead, which was useless.) – kjo Aug 05 '21 at 21:56
  • 1
    the defcustom form for ansi-color-names-vector has a :set argument of ansi-color-map-update; that's the function that gets called whenever the variable is changed via customize. – Tyler Aug 05 '21 at 22:31
  • That's *very* good to know. Thank you!!! – kjo Aug 08 '21 at 23:10
  • Please note ansi color names vector was made obsolete. You have to customize faces `ansi-color-COLOR_NAME` eg. `ansi-color-red`, `ansi-color-yellow`, etc. – ocodo Sep 08 '22 at 04:38