Reputation: 1
I am writing a user command as an alias that use awk printing output in different colors.
The little snippet I came up with works fine in KDE Konsole but not in xterm or gnome-terminal.
My shell is a BASH on SLES11 and the terminal is set to XTERM
myuser@myhost:~> env |grep -i term
TERM=xterm
COLORTERM=1
The alias is defined as follows:
alias myCustomPS="\
awk '{ \
gsub(/\.CONTEXT/,\"\", \$11); \
split(\$11,v,\"_D\"); \
split(\$13,h,\".\"); \
if (\$1==\"usr1\")
printf \"pid [\033[1;37;48;2;0;0;128m %5s \033[0m] [\033[1;37;48;2;0;0;128m %.8s \033[0m] \033[1;37;48;2;0;0;128m %-8.10s \033[0m D%-8s\n\", \$2, \$1, h[1], v[2]; \
else if (\$1==\"usr2\") \
printf \"pid [\033[1;37;48;2;0;170;170m %5s \033[0m] [\033[1;37;48;2;0;170;170m %.8s \033[0m] \033[1;37;48;2;0;170;170m %-8.10s \033[0m D%-8s\n\", \$2, \$1, h[1], v[2]; }'"
the output I get is displaying correctly ONLY in Konsole.
Both xterm and gnome-terminal instead don't show it correctly. In Xterm no color at all is shown, in gnome-terminal only the font color is shown, no background.
any idea, or alternative ways to universally colorize the awk output? Thanks, Roberto
Upvotes: 0
Views: 263
Reputation: 54583
The snippet uses the RGB flavor "2" in the escape sequence, which should work with xterm after patch #282 (which seems a little old, but SLSE 11 is a few months older than that).
If you must hardcode things, the RGB flavor "5" is more portable. But portable applications use something like tput rather than relying on constants.
The "2" referred to is in this string (repeated several times):
\033[1;37;48;2;0;0;128m
^
and is mentioned in XTerm Control Sequences in the paragraph discussing ISO-8613-6.
Upvotes: 1