-1

I am trying to set colors using tput setb or setab function but I am unable to get colors. On the positive side tput bold , underline like functions are working. I am unable to find any reasons for setb function issue.

print $(tput bold)"Text is bold"$(tput sgr0)

 print  $(tput bold)"Text is bold"$(tput sgr0)

Could you please help me to use the tput set function to create colors?

I am using putty 0.65 release, TERM=xterm-256color and AIX version = 7.1

I have tried using a different method from google as below. But I would like to use tput set for easy purpose rather than hard coding color values. Kindly help me to understand.

__GREEN='\033[0;32m'
print  ${__GREEN}$(tput bold)"Green color Bold" $(tput sgr0)

print  ${__GREEN}$(tput bold)"Green color Bold" $(tput sgr0)

  • Are you just experimenting, or actually want to change colors? If the latter, use escape sequences `ESC [ 30+fgcolorno m` and ESC [ 40+bgcolorno m` More info: https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters – Lorinczy Zsigmond Mar 22 '18 at 09:01

2 Answers2

0

The setb (and setf) capabilities are not provided in the terminal description because they're used for non-ANSI colors. Use setab (and setaf).

  • To change the current foreground or background color on a Tektronix-type terminal, use setaf (set ANSI foreground) and setab (set ANSI background) or setf (set foreground) and setb (set background). These take one parameter, the color number. The SVr4 documentation describes only setaf/setab; the XPG4 draft says that "If the terminal supports ANSI escape sequences to set background and foreground, they should be coded as setaf and setab, respectively.

ncurses' terminfo manpage says this:

  • If the terminal supports other escape sequences to set background and foreground, they should be coded as setf and setb, respectively. The vidputs and the refresh(3x) functions use the setaf and setab capabilities if they are defined.

Colors are numbered, either way:

for n in 0 1 2 3 4 5 6 7;do tput setab $n;echo background $n;done; tput sgr0
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
0

I have defined below and it worked. Thanks!

 __GREEN='\033[0;32m'
 __NC='\033[0m' # No Color

 print -n ${__GREEN}$(tput bold)
 banner  DEVELOPER
 print -n $(tput sgr0)${__NC}

I am using AIX Lpar and putty