9

Is there a way to alter all the available colors in console / virtual terminal?
By console, I mean what you get after pressing CTRL + ALT + F1 and not anything like xterm or urxvt. So, I guess that would mean alter

I can change 8 of the colors using escape sequences like so:

echo -en "\e]PY######"

where Y is the numerical id of the color (0 to 7) and ###### is the hex color value.

My ultimate goal is to port the solarized color scheme to the console, because I want to look vim all the same regardless of whether I'm in console or X.

Any suggestions on this?

htop in xterm:
htop in xterm, solarized colors

htop in console, after applying the 8 colors:
htop in console, after applying the 8 colors I could

5
  • 2
    TTY framebuffer console has no way to have more than 8-16 colors without kernel hacking, see this quote: "Although the Linux frame-buffer supports 256 (or more) colors, the Linux console driver does not; therefore, console applications are still limited to 16 colors on the Linux console, frame-buffer or not." So you have no more than 16 or 8 colors. There is tutorial how to change colors for framebuffer terminal (aka ctrl+alt+1) using same commands as you described in ~/.bashrc: phraktured.net/linux-console-colors.html
    – IBr
    Commented Apr 26, 2013 at 18:16
  • Yeah, i know. As I get 16 different colors I supposed to have 16 colors available, but can only configure 8 of them. 16 would be totaly enough for me. But 8 ist not. Commented Apr 26, 2013 at 20:11
  • To be more specific: The code given in your link is exactly what I tried, but the hex values with numerical id above 7 (8 to F) seem to be ignored by the console. Could you test if the code in your link is working for you? Commented Apr 26, 2013 at 20:13
  • @IBr I was wrong, it is definetly working. The problem was that I thought color id 8 would be white, but it is F as seen in your link. Do you want to answer the question, so I can close it? Commented Apr 28, 2013 at 12:06
  • Ok I answered for others to find the solution easier, you can close it. Thought I think that you had worked it out yourself.
    – IBr
    Commented Apr 29, 2013 at 17:56

2 Answers 2

6

TTY framebuffer console has no way to have more than 8-16 colors without kernel hacking, see this quote: "Although the Linux frame-buffer supports 256 (or more) colors, the Linux console driver does not; therefore, console applications are still limited to 16 colors on the Linux console, frame-buffer or not."

So you can have no more than 16 or 8 colors. There is tutorial how to change colors for framebuffer terminal (aka ctrl+alt+1) using same commands as you described in ~/.bashrc: colors in TTY tutorial

4
5

Try out this bash function in the console. Fittingly, it doesn't work in an X terminal (I think because of the tabs). Especially check out the three files used last, namely

/sys/module/vt/parameters/default_red
/sys/module/vt/parameters/default_grn
/sys/module/vt/parameters/default_blu

clr () {
    clear # GFX bug otherwise
    setterm -regtabs 4
    Color_names="bla red gre yel blu mag cya whi"
    Color_arr=($Color_names)

    tput setaf 4
    tput setab 7
    echo -n "            normal             "
    tput sgr0

    echo -n " "

    tput setaf 7
    tput setab 4   
    echo "            bright             "

    tput sgr0
    for cmd in sgr0 bold
    do
        tput $cmd
        for m in 0 1 2 3 4 5 6 7
        do
            tput setaf $m
            echo -n ${Color_arr[$m]}" "
        done
    done
    echo

    tput sgr0
    cat /sys/module/vt/parameters/default_red \
        /sys/module/vt/parameters/default_grn \
        /sys/module/vt/parameters/default_blu | sed s/,0/", "/g | \
                                                sed s/^0/" "/g | \
                                                tr "," "\t"
}

Edit in response to comment

For example, change the second digit in the green file (sys/module/vt/parameters/default_grn) to 170 - this will give the second color (with index 1) as much green as red, and no blue (at least in my case, because I have the corresponding digit in default_red 170, and 0 in default_blu).

Now, type tput setaf 1; echo hi. Here you put the foreground color to the color with index 1 (the one you changed), then you print it. (Note the oneliner with a colon to separate the commands, else your prompt may reset the tput in between.)

If it appears the same as always, try echo -n '\033]R' and then the tput line again. Now, both "hi"s should be sort of yellow.

Let my know if you get it to work (or not).

4
  • I might be missing something, but this displays me the different colors. Can you explain the contents of those three files to me? Commented Apr 27, 2013 at 11:33
  • @DanielOertwig: Made an edit. Commented Apr 29, 2013 at 8:00
  • Unfortunately trying to change one of the 3 files results in an error ("fsync failed" - vim as root). Commented Oct 9, 2013 at 6:47
  • @DanielOertwig: Check out this page for some better material on this (hopefully). Commented Nov 22, 2013 at 22:36

You must log in to answer this question.

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