7

I've just started using dwm a couple days ago and I'm using xterm (uxterm) as a terminal emulator.

However, I'm noticing that certain applications (like vi/vim, ls, and others) that output in color are using bright colors and (sometimes) bold fonts. My terminal's background color is a dark pastel so I'd like the colors to match.

How can I change these colors, is there a way to use #xxxxxx colors?

4 Answers 4

14

Xterm is configured via X resources. This is how you might configure it for white on black, with a lighter blue than the default (adjust the color as you see fit, obviously):

XTerm.VT100.background:         Black
XTerm.VT100.color0:             Black
XTerm.VT100.color1:             Red
XTerm.VT100.color2:             Green
XTerm.VT100.color3:             Yellow
XTerm.VT100.color4:             CornflowerBlue
XTerm.VT100.color5:             Magenta
XTerm.VT100.color6:             Cyan
XTerm.VT100.color7:             White
XTerm.VT100.colorBD:            White
XTerm.VT100.colorBDMode:        true
XTerm.VT100.colorUL:            Yellow
XTerm.VT100.colorULMode:        true
XTerm.VT100.cursorColor:        Red
XTerm.VT100.foreground:         White

You can use X color names (you can see all the color names with xcolors or in a file called rgb.txt which may be somewhere under /etc/X11, /usr/X11 or /usr/share/X11 or some similar location depending on your system) or #RRGGBB. colorBD is the color used for bold; with colorBDMode set to false (the default), this setting is ignored and bold text is displayed in a bold font. The same goes for colorUL, colorULMode and underline. You can go beyond color8 (up to color255, or less depending on the xterm version and compile-time configuration). color8 through color15 correspond to 0–7 with bold; colors beyond 16 are rarely used by applications unless you've explicitly configured them.

Put these settings into a file called ~/.Xdefaults. Most systems load this file automatically when you log in. If yours doesn't, add this command to your X startup script:

xrdb -merge ~/.Xdefaults

To test the appearance of foreground color 42 over background color 17, run this in a shell in that terminal:

printf '\033[38;5;%dm\033[48;5;%dm%s\033[0m\n' 42 17 "Hello, world."

If your xterm is compiled without extended color support, you'll need to use the classical control sequences:

printf '\033[3%dm\033[4%dm%s\033[0m\n' 4 1 "Hello, world."

The foreground and background color must be in the range 0–7 in that case. If your xterm is compiled with 16-color support, replace [3 and [4 by [9 and [10 respectively to select the bright versions (colors 8–15).

1
  • I've been toying around with this and it seems to change the colors of ls you need to edit the /etc/DIR_COLORS file. I see color codes in here, but I'm only allowed a certain number of them. Namely, 42 doesn't work but instead gives me a green background.
    – nopcorn
    Commented Aug 16, 2011 at 22:10
3

You can do that by editing the .Xdefaults file in your home directory. You can just try some other people available .Xdefaults settings, like this one that uses "zenburn" dark color scheme. You'll use just the lines begining with "xterm". Just tested that it works this way for uxterm as well. If for some reason it doesn't for you, change the line beginnings to "uxterm".

2
0

Since you mentioned that you are using dwm: you can also leave the X resources (as mentioned in the other answers) alone and instead modify the command that invokes the terminal. In my config.h I have modified the terminal command to read

static const char *termcmd[]  = { "uxterm", "+cm", "+dc", "-bg", "black", "-fg", "gold", NULL };

Which enables colors and uses gold on black See https://linux.die.net/man/1/xterm for the available options. (Notice that you have to recompile dwm after changing it's config.)

0

TL;DR

How can I change these colors[?]

You can change these colors with an .Xresources file.

[I]s there a way to use #xxxxxx colors?

Yes. For example xterm*color1: ffa70a ( though I don't suggest lightsalmon as your xterm*color1 ). Note that, I imagine among other specifications, you can use an equivalent option - xterm*color1: rgb:ff/a7/0a - which I think is a bit more readable (especially for people just learning *NIX systems; if you feel better with the #ffa70a, feel free to use it).

An example of making all colors less bright than the defaults is:

$ cd
$ test -f .Xresources && \
  cp .Xresources .Xresources.$(date '%s').bak \
  # backing up existing .Xresources if it exists
$ test -f .Xresources || touch .Xresources \
  # creating .Xresources if it doesn't exist

Edit ~/.Xresources using your favorite editor For this example, the file should end up as

xterm*color1: gray40
xterm*color2: red5
xterm*color3: green5
xterm*color4: yellow5
xterm*color5: magenta5
xterm*color6: cyan5
xterm*color7: white5
xterm*color8: gray50
xterm*color9: red2
xterm*color10: green2
xterm*color11: yellow2
xterm*color13: magenta2
xterm*color14: cyan2
xterm*color15: white2

Run

$ xrdb -merge ~/.Xresources

Then, your

$ xterm &

should bring up something less bright.

I should mention one resource in the TL;DR, because it has been so useful for me with xterm, etc.

Thomas E. Dickey's Invisible Island: XTerm FAQs


Details

@Gilles_'SO-_stop_being_evil' has a great answer - I especially liked the information on how to preview a color from the terminal with printf and the escapes for the ascii color codes.

The answer from @Gilles helped me to find out how to fix my too-bright XTerm stuff. The part that was bothering me was the bright green of the <username>@<machine-name>. (See Note {1} for my reasons not to have a screenshot.) I wasn't able to get the change using any of the listed colors, and I didn't really understand how to use the info that

If your xterm is compiled with 16-color support, replace [3 and [4 by [9 and [10 respectively to select the bright versions (colors 8–15).

I was led to look at the documentation from X.org. If that previous link, which points to

https://www.x.org/releases/X11R6.7.0/doc/xterm.1.html#:~:text=color0%20%28class%20Color0%29

doesn't take you to the part of the page with "color0 (class Color0)", then do a Ctrl+f for "color0 (class Color0)". In the docs, there's nothing listed after color0-color6, but after color7 one can read

These specify the colors for the ISO-6429 extension. The defaults are, respectively, ...

After this, the colors match the table from @Gilles, but I show what's in the docs. I repeat it to give a second way of seeing it, as well as to add emphasis with bold text and notes I've added inside square brackets.

... The defaults are, respectively,
black [meaning color0],
red3 [meaning color1],
green3 [color2],
yellow3 [color3],
DodgerBlue1 [color4],
    [ Note that linux.die.net/man/1/xterm and
                        man xterm | grep -B9 -A32 color4
      both list 'a customizable dark blue'
      for what matches with color4. ]
magenta3 [color5], cyan3 [color6], and gray90 [color7].

For the RGB (or other color-space) coordinates of these named colors, find X11's rgb.txt using find /usr/share/ -type f -name "rgb.txt" 2>&1 | grep -i "X11", or, if that doesn't work, find /usr/ -type f -name "rgb.txt" 2>&1 | grep -i "X11". I've seen a lot of resources that list it at /usr/X11R6/lib/X11/rgb.txt, but on my machine (see Note 2) it's at /usr/share/X11/rgb.txt.

Further, there's nothing listed after color8-color14, but after color15 one can read

These specify the colors for the ISO-6429 extension if the bold attribute is also enabled. The default resource values are respectively,
gray30 [color8],
red [color9],
green [color10],
yellow [color11],
SteelBlue1 [color12],
    [ Note that linux.die.net/man/1/xterm and
                        man xterm | grep -m1 -B34 -A5 color15
      both list 'a customizable light blue'
      for what matches with color12. ]
magenta [color13],
cyan [color14],
and white [color15].

As for 'if the bold attribute is enabled', this is the case unless you've changed the defaults, for example by adding xterm*boldMode: false to your .Xresources or .Xdefaults.

With all this information, I was able to fix my too-bright-green problem by making an .Xresources file in my home directory ( cd ; touch .Xresources ). I chose this instead of .Xdefaults, because I read somewhere that .Xdefaults is deprecated. I don't have the source for that, sadly. Then, I added the line,

xterm*color10: green2

(green2 is less bright that green and more bright than green3)

and running

xrdb -merge ~/.Xresources

To make the other bold colors less bright, one could have in one's .Xresources the following:

xterm*color8: gray20
xterm*color9: red2
xterm*color10: green2
xterm*color11: yellow2
xterm*color13: magenta2
xterm*color14: cyan2
xterm*color15: white2

You could also make everything less bright by doing something like xterm*color3: green3 with xterm*color10:green6, etc. for the other pairs of colors.

You can also use hex ( #xxxxxx ) and RGB decimal values. I don't doubt that you can use other specifications of colors, too. So, in answer to your questions:

How can I change these colors, is there a way to use #xxxxxx colors?

You can change these colors with an .Xresources file.

AND

You can use #xxxxxx colors with, e.g. xterm*color10: #00ee00

(respectively).


Notes:
{1} I would post a screenshot, but as of now (2021-12-23), StackExchange sites seem to be having trouble with attached images, and I can't put a backup from the Wayback Machine here at work.
{2} The following command and output show my machine information. I'm running RHEL 8, RHEL standing for Red Hat Enterprise Linux.

$ uname -a
Linux MYMACHINE 4.18.0-240.10.1.el8_3.x86_64 #1 SMP Wed Dec 16 03:30:52 EST 2020 x86_64 x86_64 x86_64 GNU/Linux

Other useful resources:
Color names and locations in color spaces
An SO answer that has useful comments describing what certain color[1]?[0-9] will affect
ArchLinux: Understanding Xdefault terminal colors
What are the colors[0..15] used for in xterm? Examples of application-specific .xresources
AstroBetter - Customizing xTerm and Terminal: colors , be careful to back up your LS_COLORS environment variable, e.g. echo $LS_COLORS > ~/.env_LS_COLORS.$(date +'%s').bak before trying these things.
Very close to what I ended up using, note that this disables the bold, as I ended up doing.
Perhaps the most useful: Thomas E. Dickey's Invisible Island: XTerm FAQs

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .