\e[7m
is the code for reverse video (also often used for the standout mode) in most terminals. What that does though is replace the background colour with the foreground colour and the foreground colour with the background colour, it's not reverse-video as in a photographic negative.
For the photographic negative, a few terminals support the:
\e[38;2;RED;GREEN;BLUEm # for foreground
\e[48;2;RED;GREEN;BLUEm # for background
escape sequences, where RED
, GREEN
, BLUE
is a decimal number from 0 to 255. That tells the terminal to pick a colour in their palette that is closest to that RGB specification.
So you could do:
straight_color() {
printf '\33[48;2;%s;%s;%sm\33[38;2;%s;%s;%sm' "$@"
}
negative_color() {
for c do
set -- "$@" "$((255 - c))"
shift
done
straightcolor "$@"
}
And then for instance:
straight_color 255 0 0 255 255 255
For bright white foreground on bright red background and:
negative_color 255 0 0 255 255 255
for the negative (black on bright cyan).
tput rev
. standout (smso) is usually implemented with reverse video, but not necessarily, or it could be bold+reverse for instance. – Stéphane Chazelas Jul 03 '17 at 10:34rev
stillrmso
? – Chris Davies Jul 03 '17 at 17:18sgr0
which would revert all attributes (including color) to their default. rmso will work on terminals where rev and smso are the same but not necessarily on others (and like smso could change other attributes) – Stéphane Chazelas Jul 04 '17 at 06:11sgr0
thank you very much. – Chris Davies Jul 04 '17 at 06:43