Change colors in console/virtual terminal

8,712

Solution 1

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

Solution 2

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).

Share:
8,712

Related videos on Youtube

Daniel Jour
Author by

Daniel Jour

Updated on September 18, 2022

Comments

  • Daniel Jour
    Daniel Jour over 1 year

    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

    • Admin
      Admin about 11 years
      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
    • Admin
      Admin about 11 years
      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.
    • Admin
      Admin about 11 years
      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?
    • Admin
      Admin about 11 years
      @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?
    • Admin
      Admin about 11 years
      Ok I answered for others to find the solution easier, you can close it. Thought I think that you had worked it out yourself.
  • Emanuel Berg
    Emanuel Berg about 11 years
    @DanielOertwig: Made an edit.
  • Daniel Jour
    Daniel Jour over 10 years
    Unfortunately trying to change one of the 3 files results in an error ("fsync failed" - vim as root).
  • Emanuel Berg
    Emanuel Berg over 10 years
    @DanielOertwig: Check out this page for some better material on this (hopefully).
  • Antonios Hadjigeorgalis
    Antonios Hadjigeorgalis over 8 years
    The link is broken
  • JdeBP
    JdeBP over 6 years
    The "Solarized" colour schemes are just 16 colours, note.
  • Paul Wratt
    Paul Wratt about 4 years
  • Paul Wratt
    Paul Wratt about 4 years