2

I noticed that with a normal 16 color xterm I can reassign the color values in the .Xresources file using the "*color0: #" through "*color15: #" commands.

I switched to xterm-256color with the intention of using more colors but color reassignments don't seem to be working anymore.

Is there a way to reassign the 256 color palette? Or is there another xterm setting to allow for more color options?

  • Paste your ~/.Xresources. – jasonwryan Dec 7 '16 at 21:20
1

You can program the color palette using escape sequences, or better, using tput.

There is a script in xterm's sources which demonstrates the escape sequences:

256 colors (default)

and reversing the palette with the script:

256 colors (reversed)

That's for xterm of course. Some of the xterm look-alikes took a while to implement that feature (partially), and some still haven't done that.

You could compile xterm to support 256 color resources, but lose UTF-8, as noted in the manual:

           Resources past color15 are available as a compile-time option.
           Due to a hardcoded limit in the X libraries on the total number
           of resources (to 400), the resources for 256-colors are omitted
           when wide-character support and luit are enabled.  Besides
           inconsistent behavior if only part of the resources were
           allowed, determining the exact cutoff is difficult, and the X
           libraries tend to crash if the number of resources exceeds the
           limit.  The color palette is still initialized to the same
           default values, and can be modified via control sequences.
  • But can't it be done from the X resources? Doing it from inside the terminal is inconvenient, for example it isn't automatic when you run something other than your usual interactive shell in the terminal. – Gilles Dec 8 '16 at 23:19
0

I can't tell whether "*color16" and friends work in .Xresources and if not then why not.

You can, however, dynamically change the actual colors using the OSC 4 escape sequences, e.g. to change color 16 to #abcdef you should do something like this:

echo -ne '\e]4;16;#abcdef\a'

You could place such statements in your .bashrc, with the condition that the output goes to a terminal (if [ -t 1 ]; then...) or that the shell is interactive (look for "i" in $-) so that you don't break scp/rsync.

This is supported by some terminal emulators, including xterm and vte (gnome-terminal etc.), but not by quite a few others, e.g. konsole.

The first 16 colors are different across all terminal emulators, and hence they offer a setting for the preferred values (via config file or in the graphical preferences dialog, depending on the emulator). The additional 232 (6x6x6 color cube + 24 grayscale) colors, however, are exactly the same in all terminal emulators according to my knowledge. By redefining them you'll diverge from "everyone" which might not be the best idea.

You could also take a look at true color support. It has a quite limited availability, though. It is supported by some popular terminal emulators such as gnome-terminal and konsole, but alas not by other popular ones like xterm or uxrvt. Also it's hardly supported by any apps, but it's easy to use them if you're manually emitting the escape sequences (e.g. in your shell prompt or a simple script).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.