Some terminals like xterm allow to redefine the colors via resource files or dynamically, and if it's exposed correctly in the terminfo entry for $TERM, you can do it with:
tput initc 4 1000 0 0
Change ANSI color 4 (normally blue) to RGB (1000, 0 0), that is bright red.
If the terminal doesn't support redefining colours (see infocmp -1 | grep initc
), you can also, for applications that use terminfo, trick them into sending different escape sequences to request colour 4 (blue).
infocmp -x > terminal.info
Edit terminal.info
, replace the name of the terminal with something like "myterm", and edit the "setab" property (set ANSI background).
Instead of
setab=\E[4%p1%dm
That is:
tput setab 4
sends ^[[44m, change it to:
setab=\E[4%?%p1%{4}%=%t1%e%p1%d%;m
The %? ....
, is an if-then-else, to say send "1" when asked for "4" and the requested one otherwise.
So
tput setab 4
will send ^[[41m
, (red) and tput setab 5
will send ^[[45m
Then, compile it with:
TERMINFO=$HOME/.terminfo tic -x terminal.info
and use it as:
TERMINFO=$HOME/.terminfo TERM=myterm the-application-to-trick
That only works if the application uses the terminfo database to send sequences to the terminal.
UPDATE:
A newer version of tmux
now allows this: https://stackoverflow.com/a/33553372/1204312
There is currently no way to do this.
See this accepted answer on stackoverflow which suggests changing pane-borders instead.
You can set values for pane-active-border-style
and pane-border-style
in your ~/.tmux.conf
.
See this answer for more details configuring these values (and some inconsistencies between tmux versions).
Best Answer
As far as I know, there's no way to query the colors of the terminal emulator. You can change them with
\e]4;NUMBER;#RRGGBB\a
(whereNUMBER
is the terminal color number (0–7 for light colors, 8–15 for bright colors) and#RRGGBB
is a hexadecimal RGB color value) if your terminal supports that sequence (reference: ctlseqs).Powerful color scheme mechanisms often have a dark or light background setting that you must supply to indicate whether you have a black or dark gray background, or a white or light gray background.
When you're configuring for yourself, it's usually enough to decide you'll always use the same background color.