1830898 Members
3127 Online
110017 Solutions
New Discussion

Re: write with color

 
Caesar_3
Esteemed Contributor

write with color

Hello!

How can i write in the terminal (xterm)
with colors.
I write a script that read a file and it
must write some lines with color.
How can i do it?
I use HPUX 11.0, i can write sh, perl, c
no metter just to get the efect.

Caesar
6 REPLIES 6
Shannon Petry
Honored Contributor

Re: write with color

ncurses

There are Perl modules, C libraries, and C++ libraries for this.

I'd recommend you get a book though, it's tricky at best.

Regards,
Shannon
Microsoft. When do you want a virus today?
John Meissner
Esteemed Contributor

Re: write with color

Caesar - I know what you mean. I too wish that HP-UX would use colors (like linux does).

The best I can tell you is how to highlight a string of text.

at the beginning of your script put these two lines:

BOLD="`tput smso`"
NORMAL="`tput rmso`"

Then to make something bold (highlighted) do it like this:

echo "${BOLD}bla bla bla${NORMAL}"

and "bla bla bla" will be highlighted.
All paths lead to destiny
Dario_1
Trusted Contributor

Re: write with color

Hi Caesar:

I think that the best you can do is bold or blink. Check this out:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xec0e36e69499d611abdb0090277a778c,00.html

Regards,

DR
Bill Hassell
Honored Contributor

Re: write with color

man terminfo

The tput command can generate a terminal-specific escape sequence for any of the features listed for the terminfo database entry of that terminal. To see what is defined for the current terminal:

untic $TERM

In all cases, $TERM must match the terminal you are using. If your profile sets $TERM using ttytype, then the untic command will show the features available for that terminal. Decode the untic entries using the man page for terminfo (which defines the curses library calls).


Bill Hassell, sysadmin
Caesar_3
Esteemed Contributor

Re: write with color

Thanks for the help!

Caesar
curt larson_1
Honored Contributor

Re: write with color

here are some example tputs to set colors.

# sets parameters for highlighting or colorizing text
bold="$(tput smso 2>/dev/null)"
undl="$(tput smul 2>/dev/null)"
norm="$(tput rmso 2>/dev/null)"

bla="$(tput setaf 0 2>/dev/null)"
red="$(tput setaf 1 2>/dev/null)"
gre="$(tput setaf 2 2>/dev/null)"
yel="$(tput setaf 3 2>/dev/null)"
blu="$(tput setaf 4 2>/dev/null)"
pur="$(tput setaf 5 2>/dev/null)"
cya="$(tput setaf 6 2>/dev/null)"
whi="$(tput setaf 7 2>/dev/null)"

off="$(tput sgr0 2>/dev/null)"
HI="$(tput smso 2>/dev/null)"
LO="$(tput sgr0 2>/dev/null)"

but as bill pointed out, these are terminal specific esacape sequences. and xterm doesn't have any. these will work for a dtterm. you'll have to test what capabilities the terminal has and set values appropriately. such as for an xterm you could use bold for yellow and bold inverse for red and underline for blue, etc. This way if someone is using an xterm there is some differentiation in the visual presentation albeit not colors. and if someone is using an dtterm their visual presentation would be differentiated by colors.