18

By "alter colors", I mean something like change black from #000000 to #111111, and by "TTY console", I mean what you get when you do Ctrl+Alt+F1 from X11, not a terminal emulator like xterm or urxvt.

I'm using Arch Linux, but I think it has more to do with the program providing the TTY (agetty, I think).

Austin Hyde
  • 1,054
  • 4
  • 13
  • 22
  • Terminals don't operate in terms of hex colors - they use color codes like those found in "/etc/shell-colors". – new123456 Jul 23 '11 at 04:55
  • 1
    @new123456 - I don't have any file called "shell-colors" anywhere under `/` – Austin Hyde Jul 23 '11 at 18:27
  • Huh. You don't state your distribution here - I am running Zenwalk, so you're distribution may vary. Search for `color in bash` to get a list of all the escapes. – new123456 Jul 23 '11 at 21:24
  • 2
    @new123456 - I did mention that I was using Arch, and I'm not looking for bash escape sequences for colors, like `\e[0;30m` for black, I'm looking for a way to customize the actual color for each named color. – Austin Hyde Jul 23 '11 at 23:11
  • 1. Sorry - I look at tags first ;) 2. Just information, not entirely pertinent to the question but pertinent to the domain. – new123456 Jul 24 '11 at 02:16

4 Answers4

14

This is entirely possible and is something I do on my Arch setup.

You could drop something like this in a shell script and have it run at login:

if [ "$TERM" = "linux" ]; then
    echo -en "\e]P0151515" # Black
    echo -en "\e]P1ac4142" # Red
    ...
    echo -en "\e]PEac4142" # Bright Cyan
    echo -en "\e]PFac4142" # Bright White
    clear # Clear artifacts
fi

The \e]P0 to \e]PF (base 16) are the escape sequences you need to set the 16 (8 half bright, 8 bright) colours. After which you put your desired replacement colour e.g. 151515.

Chris Kempson
  • 213
  • 2
  • 8
  • doesn't seem to work in ubuntu 16.04 with bash fwiw – Gordon Seidoh Worley Sep 20 '16 at 17:01
  • Since `echo -en` is not POSIX shell compliant (POSIX does not define a `-e` argument for `echo`), a more portable method would be to use `printf` with an octal escape, such as `printf "\033]P0151515"`. `\033` is equivalent to the `0x1b` character that `\e` outputs in bash with `echo -e`. If you don't use bash as your primary shell, that is. – Wyatt Ward Jun 05 '21 at 22:16
6

The setterm command is what you're looking for.

setterm -foreground black -background white

EDIT

No, there is no way to alter the names of the colors as you requested. They are not referenced that way anywhere in curses, terminfo, or the terminal itself. You could change the definitions of the color indexes (0-15 i think) by editing the kernel source and recompiling.

h0tw1r3
  • 1,776
  • 14
  • 13
2

This is the best command I know of:

setterm -clear all -foreground green -bold -store

You can only have 8 different color as far as I can tell. Maybe some more by using bright in front of basic 8?

Giacomo1968
  • 53,069
  • 19
  • 162
  • 212
Shubham Chaudhary
  • 2,947
  • 1
  • 14
  • 6
1

How an extra addition: the current valid answer about

setterm -foreground black -background white

is valid and works, it has one advantage, it allows customize any color you like, the disadvantage is that is temporal, if you run either htop or w3m <url> and exit, then the tty returns to the original setting.

if you use (according with man setterm)

setterm --inversescreen [on|off]

it applies an inversion of colors between foreground and background from white/black to black/white respectively. The advantage is that is permanent, you can run either htop or w3m <url> and exit, then the tty keeps the inverted setting yet. The disadvantage is that the colors can't be customized - it means white and black are always used

Manuel Jordan
  • 269
  • 5
  • 15