2

I'm printing out all the 255 xterm-colors (background) using ANSI extended set background sequences, like so: \033[48;5;%dm (%d is substituted from 0-255). I set the xterm window color using #eee9bf via .Xdefaults with xrdb:

XTerm*background: LemonChiffon2

How is it possible that the ANSI colors don't match the #eee9bf when I inspect visually with a little help from gimp color picker? The xterm color gamut is from 0-255 only, so what is going on here - how is xterm converting #xxxxxx into 0-255? How does ANSI fit into this?

import sys

bgn_marker = '\033[48;5;%dm '
fgn_marker = '\033[%dm'
end_marker = '\033[0m'

text = "11. hello, how are you - today is not a it;s d'ay"
space = ' ' * 40

def burp(bg):
    print '######################## %d ####################################' % bg
    for fg in range(30,38):
        print (bgn_marker + fgn_marker + text + space + end_marker) % (bg, fg)

(What I'm trying to do is pick a decent background for xterm that doesn't hide the ANSI colors that are often displayed when you use vim/dmesg etc.)

3

ANSI has no role in this process. It never did, except for naming convenience. ANSI defined a set of 8 colors which most people number 0-7. When extending the scheme to 16-, 88- and 256-colors, it was convenient to make an array of color values which are addressed by the same type of index.

The X server (and your display configuration) do play a part.

xterm takes the hexadecimal value from your resources or indirectly via a name in rgb.txt and asks the X server for a color "close" to the R/G/B value. The server may (and often does) approximate the colors. In xterm's source-code, a good place to start reading is (appropriately enough) AllocateAnsiColor.

Further reading:

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.