[Discuss] sed and ANSI sequences

Bill Bogstad bogstad at pobox.com
Mon Oct 17 13:54:59 EDT 2011


On Thu, Oct 13, 2011 at 3:00 PM, David Kramer <david at thekramers.net> wrote:
> I have a script at work that colorizes command outputs.  I've mentioned it here before.  I have
> the colors defined in environment variables:
> COLOR_ERROR='\e[37;41m'
> COLOR_GOOD='\e[32;40m'
> COLOR_RESET='\e[0m'
> COLOR_WARN='\e[33;40m'

Have you considered using the tput command to get the appropriate
sequences for whatever terminal you are on rather then hardcoding
them?  I've only used it to "standout" text, but the terminfo(5)
manual page implies there is support for color as well.

I've used

SMSO="`tput smso`"
RMSO="`tput rmso`"

to get the sequences to get in and out of standout (reverse video)
mode.  I was able to coax some color sequences out of tput pretty
quickly, but the documentation is pretty baroque and I don't know if
you will be able to get exactly what you have now or not.

Good Luck,
Bill Bogstad



More information about the Discuss mailing list