Subject: Re: reverse text
To: George Georgalis <george@galis.org>
From: Johnny Billquist <bqt@softjar.se>
List: netbsd-help
Date: 09/25/2006 11:26:26
To expand a little. This has nothing to do with bash or NetBSD and so 
on... What we're talking about here is the ANSI escape codes to select 
graphic rendition (SGR). They are documented by ANSI, and you can 
probably find them in any number of places on the net.

Good things to know:

The general format is:

CSI <n> ; <n> ; <n> . . . m

Where CSI is the code to start an escape sequence. It can be the 8-bit 
CSI character, or the 7-bit equivalent, which is ESC [

You can then have zero or more numeric parameters, finished by a small 
'm'. Each parameter is separated from the next one with a semicolon.

If no number is given, it's the same as giving a '0'.

Parameters are:
0 - All attributes off
1 - Bold
4 - Underline
5 - Blinking
7 - Negative image
8 - Invisible image
21 - Bold off
24 - Underline off
25 - Blinking off
27 - Negative image off
28 - Invisible image off
30 - Foreground color 0 (Black)
31 - Foreground color 1 (Red)
32 - Foreground color 2 (Green)
33 - Foreground color 3 (Yellow)
34 - Foreground color 4 (Blue)
35 - Foreground color 5 (Magenta)
36 - Foreground color 6 (Cyan)
37 - Foreground color 7 (White)
39 - Default foreground color
40 - Background color 0 (Black)
41 - Background color 1 (Red)
42 - Background color 2 (Green)
43 - Background color 3 (Yellow)
44 - Background color 4 (Blue)
45 - Background color 5 (Magenta)
46 - Background color 6 (Cyan)
47 - Background color 7 (White)
49 - Default background color

Now, this is as a VT525 will interpret it. On an Xterm, I've found that 
37 and 47 are a grayish color, and not white. Also, 90-97 are lighter 
versions of the foreground colors, and 100-107 are lighter versions of 
the background colors (probably the same as if you select a color and 
select bold).

I'm not sure ANSI specifies exactly which colors to expect.

Now, given this information, your answer about light red being 1;30 is 
somwhat misleading. What you're actually doing is selecting bold, red 
text. :-) However, I'm pretty sure the end result on most terminals will 
look the same, so it's maybe not that important.

Some people might know parts of this since old times, since the VT100 
and all follow ons also implement the applicable parts of this. Color is 
not something a VT100 can do, and the 2x attributes, to actually turn 
off attributes didn't come until the VT200 series, and the same is true 
for the concealed attribute.

	Johnny


George Georgalis wrote:
> 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
> 
>