Re: white text, black background
From: Stephane CHAZELAS (stephane_chazelas_at_yahoo.fr)
Date: 05/11/03
- Next message: Peter S Tillier: "Re: Removing substring from string"
- Previous message: Stephane CHAZELAS: "Re: Help with Reg Expr"
- In reply to: Terence: "white text, black background"
- Next in thread: Chris F.A. Johnson: "Re: white text, black background"
- Reply: Chris F.A. Johnson: "Re: white text, black background"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
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
- Next message: Peter S Tillier: "Re: Removing substring from string"
- Previous message: Stephane CHAZELAS: "Re: Help with Reg Expr"
- In reply to: Terence: "white text, black background"
- Next in thread: Chris F.A. Johnson: "Re: white text, black background"
- Reply: Chris F.A. Johnson: "Re: white text, black background"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|