2
1
There are 256 terminal color escapes available:
- 8 "system" colors (0 - 7)
- 8 "bright" system colors (8 - 15)
- 216, or 6*6*6 "RGB" colors (16 - 231)
- 24 "grayscale" colors (232 - 255)
The "RGB" colors are what I'm wondering about.
The first six colors, from 16 to 21, map to the following hex RGB values:
- 16: 000000
- 17: 000054
- 18: 000087
- 19: 0000af
- 20: 0000d7
- 21: 0000ff
Now the blue values only, in decimal:
- 16: 0
- 17: 84
- 18: 135
- 19: 175
- 20: 215
- 21: 255
In other words, the RGB value goes up by 84, then 51 (84 + 51 = 135), then 40 the rest of the way.
This cycle of 6 values from 0 to 255 is repeated 36 times, first with blue, then green, then red, eventually forming our "cube" of 216 terminal colors:
My question is: Why?
Does anyone know if there is a historical/technical reason for this, or was it just an arbitrary decision made by whoever had to decide what the color codes meant? Did this mapping come to exist before RGB was such a universal convention? Why not go up by 42, 42, 42, 43, 43, 43?
For me, color number 17 is #00005F (tested in xterm, gnome-terminal, konsole, terminology, st). That is, it goes up by 95, and then 5 times by 40. Still doesn't make too much sense, though. – egmont – 2015-04-25T21:38:39.207
"Why not go up by 42, 42, 42, 43, 43, 43?" You did the math incorrectly. 6x6x6 cube means 5 steps from one end to the other, not 6. That is, you should increment by 51 in each step. I'm really not sure though that that'd look evenly distributed to the human eye. – egmont – 2015-04-25T21:39:45.093
Just for reference, let's mention that several terminal emulators (e.g. gnome-terminal, konsole, st) support arbitrary #rrggbb colors via escape sequences. Alas, support from applications is quite poor. – egmont – 2015-04-25T21:41:23.897
To me, the big question is not why the 6x6x6 color cube looks like this. To me, the big question is why palette-free direct RGB hasn't taken over yet, and why developer are not pushing hard for this. – egmont – 2015-04-25T21:45:12.580