Subject: Re: reverse text
To: None <netbsd-help@netbsd.org>
From: George Georgalis <george@galis.org>
List: netbsd-help
Date: 09/24/2006 20:05:31
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=3Dnone 01=3Dbold 04=3Dunderscore 05=3Dblink 07=3Dreverse 08=3Dconcealed

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

echo "=1B[7mhello=1B[m"

(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


--=20
George Georgalis, systems architect, administrator <IXOYE><