[TUHS] Seeking wisdom from Unix Greybeards

Steffen Nurpmeso steffen at sdaoden.eu
Thu Nov 26 06:03:08 AEST 2020


Steffen Nurpmeso wrote in
 <20201125180048.IvtOI%steffen at sdaoden.eu>:
 |Grant Taylor wrote in
 | <9c1595cc-54a1-8af9-0c2d-083cb04dd97c at spamtrap.tnetconsulting.net>:
 ||As I find myself starting yet another project that that wants to use 
 ||ANSI control sequences for colorization of text, I find myself -- yet 
 ||again -- wondering if there is a better way to generate the output from 
 ||the code in a way that respects TERMinal capabilites.
 ||
 ||Is there a better / different control sequence that I can ~> should use 
 ||for colorizing / stylizing output that will account for the differences 
 ||in capabilities between a VT100 and XTerm?
 ||
 ||Can I wrap things that I output so that I don't send color control 
 ||sequences to a TERMinal that doesn't support them?
 |
 |  color_init() {
 |     [ -n "${NOCOLOUR}" ] && return
 |     [ -n "${MAILX_CC_TEST_NO_COLOUR}" ] && return
 |     # We do not want color for "make test > .LOG"!
 |     if (command -v stty && command -v tput) >/dev/null 2>&1 &&

Of course that subshell (..if it is one..) is not necessary, it
could be { ..; } or x&&y&&, whatever.
Must be a leftover, or whatever i have thought once i wrote this.

 |           (<&1 >/dev/null stty -a) 2>/dev/null; then
 |        { sgr0=`tput sgr0`; } 2>/dev/null
 |        [ $? -eq 0 ] || return
 |        { saf1=`tput setaf 1`; } 2>/dev/null
 |        [ $? -eq 0 ] || return
 |        { saf2=`tput setaf 2`; } 2>/dev/null
 |        [ $? -eq 0 ] || return
 |        { saf3=`tput setaf 3`; } 2>/dev/null
 |        [ $? -eq 0 ] || return
 |        { b=`tput bold`; } 2>/dev/null
 |        [ $? -eq 0 ] || return
 |
 |        COLOR_ERR_ON=${saf1}${b} COLOR_ERR_OFF=${sgr0}
 |        COLOR_WARN_ON=${saf3}${b} COLOR_WARN_OFF=${sgr0}
 |        COLOR_OK_ON=${saf2} COLOR_OK_OFF=${sgr0}
 |        unset saf1 saf2 saf3 b
 |     fi
 |}
 |
 |Is what i use for a make system.

A sh(1)-based test, to be exact.

Ciao,

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)


More information about the TUHS mailing list