------------------------------------------------------------------------------- Colors in the Linux VTs ## ## ## ## ## ## # ## ## # ## by Emanuel Berg (incal) # ## ## # ## moasenwood@zoho.eu ###### ## ## ###### updated 2022-01-28 underground experts united ------------------------------------------------------------------------------- [The Linux VTs = the Linux virtual terminals, sometimes refered to as the ttys or simply "the console".] So let's start. The 16 colors available in the Linux VTs are individually defined by combining data from three files. The three files correspond to the colors red, green, and blue. It is an implementation of the familiar additive RGB color model. [1] The files have the same format, they all consist of a single line of 16 comma-separated integers ranging from 0 to 255. So, for example, my red file looks like this: 0,255,0,190,100,180,0,150,115,255,0,255,125,250,90,210 That means the first Linux VT color shouldn't have any red (0), the second color should have full red (255), then again none for the third, after that 190 for the forth - and so on for all 16. (So 190, but how red is that? Again 255 is the maximum so 190/255.0 ~= 0.75 or 75% red.) By now you understand how it works. My green file looks like this: 0,50,155,190,100,105,180,150,115,80,185,127,125,90,255,180 Let's use color 3 as an example - the color numbers are zero-indexed so color 3 it's the forth integer from the left. We see it contains 190 amount of green as well. And finally the blue file: 0,50,0,0,255,0,180,150,115,80,0,0,255,250,255,140 So no blue for color 3. All in all, color 3 is 190 red, 190 green, and 0 blue. 190 is 'be' in hex, so if the color is described in hexadecimal pairs of 2, i.e. using the #RRGGBB notation, color 3 would indeed "be" #bebe00. Now examine your own files at: /sys/module/vt/parameters/default_red /sys/module/vt/parameters/default_grn /sys/module/vt/parameters/default_blu As seen, the colors names aren't mentioned in those files. Instead they appear in a particular order specified by the ANSI standard: [2] black red green yellow blue magenta cyan white After these follows 8 additional colors, they are supposed to be bright versions of the above colors in the same order. That means if one looks on the list above but continues further down, after white would come "bright black" - which is sometimes put to gray - then "bright red" (pink perhaps?), and so on. However, as is the case with the first 8 colors, which are the intended non-brights, you can assign _any_ RGB color to any of the 16 colors available! That said, to somewhat stick to the standard colors is recommended. But no rule without exception, as always. if you feel you don't need a bright yellow (color 11) you can turn that into for example orange - 255-127-0 (#ff7f00) is a good start ... However, if you do that, be aware that in some programs one refers to these colors by names, not number. If you redefine bright yellow to orange, in such programs you'd set something to orange by referring to it as yellow. Unless you can workaround this with aliases and the like it can get confusing. Still, should be pretty undramatic, right? Also, sticking to the intended colors probably have another, bigger advantage, because they are probably selected because they are are easily recognizable/discernable by the human eye. They will almost always work. Here [3] are the best colors I found, so far: normal bright bk r g y bl m c w bk r g y bl m c w r 0 255 0 190 100 180 0 150 115 255 0 255 125 250 90 210 g 0 50 155 190 100 105 180 150 115 80 185 127 125 90 255 180 b 0 50 0 0 255 0 180 150 115 80 0 0 255 250 255 140 Check out [4] for an example how to use sed(1) to set the colors without having to insert the values into the default_* files each time. Instead, you'd use a single file, more neatly organized, as above, the sed script will then process it and put the values into the RGB files. Some extra material: * For ls(1) to really look good, set it up with a dircolors(1) script. [5] * On OpenBSD, use colorls(1) [6] to get terminal emulator colors with ls. * If you want the same colors as in the Linux VTs in X applications (e.g., xterm), note that the values above are decimal integers in the 0-255 range (discrete base 10), but, in .Xresources you'd need their hex equivalents (base 16) to get the same value. So for example if you'd like green (color 2) defined as 0-85-0 in the VTs in X you'd get the hex value of 85 $ echo "obase=16; 85" | bc 55 and in ~/.Xresources, where the color order is the same, put: xterm*color2: #005500 Here are some zsh functions to convert between bases [7] even more easily than the bc example. GLHF! :) [1] https://en.wikipedia.org/wiki/RGB_color_model [2] https://en.wikipedia.org/wiki/ANSI_escape_code [3] https://dataswamp.org/~incal/cols/color_sets/normal.txt [4] https://dataswamp.org/~incal/cols/run [5] https://dataswamp.org/~incal/scripts/cols [6] https://undeadly.org/cgi?action=article&sid=20110225013806&mode=expanded [7] https://dataswamp.org/~incal/conf/.zsh/math ------------------------------------------------------------------------------- https://dataswamp.org/~incal/cols/www/COLORS -------------------------------------------------------------------------------