Re: reverse text

"George Georgalis" <[email protected]>
Newsgroups gmane.os.netbsd.help
Message-ID <[email protected]>
On Sun, Sep 24, 2006 at 03:02:10PM -0400, George Georgalis wrote:
>I'm looking for a way to reverse text color. (eg transpose
>foreground/background) I'm expecting to find some esc or ctrl
>sequence of characters to turn on reverse video and similarly to
>turn off.  Normally I would ssh in, from an xterm, but I'd like a
>technique to work as expected from console, as well--if that's an
>issue I can check TERM setting.
>
>The only doc I've seen on doing this is for PS1 on some shells
>but I'm looking for something generic enough that I can invoke
>with printf commands.

with a little luck and finding some bash PS1 notes... I'm answering
my own question.

# The color terminal (cterm) palette  (and bash escape codes)
# The forground Colors (background colors begin with 4 verses 3)
# Black       0;30     Dark Gray     1;30
# Red         0;31     Light Red     1;31
# Green       0;32     Light Green   1;32
# Brown       0;33     Yellow        1;33
# Blue        0;34     Light Blue    1;34
# Purple      0;35     Light Purple  1;35
# Cyan        0;36     Light Cyan    1;36
# Light Gray  0;37     White         1;37
# Attribute codes:
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed

and looking at 'script' output of some color sequences...

echo "hello"

(if this email comes in 8 bit) that's ^[[7m to start reverse and
^[[m to reset the change (note esc char, ^[).

but a more universal way might be using "tput" unfortunately
you may need the termcap(5) man page too for that.

tput mr ; printf hello ; tput me ; echo world

and this works both on console and xterm.  I never did find netbsd
doc on the color codes but this generates a palette of available
colors.

for n in `seq 0 9` ; do for u in `seq 0 57` ; do
 printf "^[[${n};${u}m${n};${u}^[[m"
done; done
echo

(note two esc characters as "^[")

// George


-- 
George Georgalis, systems architect, administrator <IXOYE><
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.