Re: white text, black background

From: Stephane CHAZELAS (stephane_chazelas_at_yahoo.fr)
Date: 05/11/03


Date: 11 May 2003 20:21:27 GMT

Terence wrote:
> In Shell script, how to print a white text with blackground?

"Black background", you mean ?

You can use the "standout" terminal capability. In most
terminals, it reverses background and foreground colours:

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

printf '%s\n' "normal${SMSO}reverse${RMSO}normal"

Or, to explicitely tell the terminal you want a black background
and a white foreground, it's much terminal dependent, because
color are specified as numbers and codes depend on the number of
colors your terminal support.

For terminals that support ANSI 8 colors, the following should
work:

blackbg=`tput setab 0`
whitefg=`tput setaf 7`
normal=`tput sgr0`

printf '%s\n' "${blackbg}${whitefg}white over black${normal}"

Note that if your terminal is XFree86 xterm, it's likely to have
at least 16 colors (it can be compiled to up to 256 color
support). Unfortunately, most terminfo entries for "xterm" claim
it has only 8 colors, but you may try:

whitefg=`TERM=xterm-16color tput setaf 15`

The point is that 7 is generally a "dark" white (or a light
grey) and 15 a true white. Some terminals fake 16 color mode by
using a different color when in bold mode, you can try:

whitefg=`tput bold; tput setaf 7`

-- 
Stéphane


Relevant Pages

  • Re: Picturing Keith (was Re: RASFF is dead!)
    ... Back when I used text-based CRT terminals, ... letters on a black background; ... typing this in an xterm window under a Cygwin X server on my Thinkpad ... whether I'm using a CRT or an LCD display. ...
    (rec.arts.sf.fandom)
  • Re: ls colors too dark on a black background terminal
    ... the colors show up too dark. ... I like my xterms with a black background also. ... one for xterms and one for everything else. ... This will make all terminals use the bright colors that stand out on a dark ...
    (Fedora)
  • Re: are you frightened, I mean, stretching other than parental textures
    ... Some terminals will be arab post-war ambulances. ... ahead warm within Ronnie when the teenage lifestyles interfere ... in support of the alive motorway. ... shifting within general Vance until his majesty undergos inadvertently. ...
    (sci.crypt)
  • Re: Using poll/kqueue/etc. instead of select
    ... terminals. ... It looks to me that if I write a bit of C support code to use, say, ... I can no longer use Ruby threads at all. ... If your SIP implementation is UDP-based, ...
    (comp.lang.ruby)
  • Release: Unicode text editor mined 2000.15
    ... Mined provides both extensive Unicode and CJK support offering many ... of terminal variations, or Han character information). ... Character encoding support enhancements: ... among different kinds of terminals as much as possible. ...
    (comp.editors)