svn commit: r214817 - head/sys/teken

Bruce Evans brde at optusnet.com.au
Fri Nov 5 14:56:13 UTC 2010


On Fri, 5 Nov 2010, Ed Schouten wrote:

> Log:
>  Partially implement the mysterious cons25 \e[x escape sequence.

CSI x is not mysterious.  It is from pccons in 386BSD (probably from
Net/2, since pccons is also in 4.4BSD).  I think it came from pc3
originally.  It is still in pccons in NetBSD, at least in 2005.

NetBSD pccons only supports CSI [0-3];*x, even in 2005.  I added CSI
[5-7];*x (set reverse video colors) to pccons in FreeBSD-1.  syscons
supported all these until recently.  Syscons also had the aliases
CSI =F/G/H/I, where F/G set normal video colors and H/I set reverse
video colors.  Now it only has F/G, and has lost its support for
setting reverse video colors.

I use CSI x in ~/.profile since it was more portable that CSI =F/G/H/I.
This broke when I downgraded to -current, so I now use the partial
workaround of setting reverse video colors in $TERMCAP:

%%%
case $TERM in
cons25)
# Broken in -current:
 	printf '\033[x\033[2;6x\033[1;0x\033[6;7x\033[5;4x'
# CSI 0x     reset to defaults
# CSI 2;6x   set ansi foreground cyan
#            default to ansi background black
# CSI 6;7x   set ansi reverse foreground white
# CSI 5;4x   set ansi reverse background blue
# Part that still works in -current:
 	printf '\033[=3F\033[=0G'
# CSI =3F    set ansi foreground cyan (not different color numbers)
# CSI =0G    set ansi background black
 	;;
linux)
# I don't remember what this does.  Probably less.
 	printf '\033[36;40m\033[1;4]\033[8]'
 	;;
esac
case $TERM in
cons25)
# Workaround for -current brokenness: set colors in termcap, and use better
# colors too.  This loses mainly the simple restore of defaults by CSI m,
# and by expanding the size of the escape sequences.
 	TERMCAP="$TERM:md=\E[1;37m:so=\E[37;44m:se=\E[39;49m:us=\E[1;33;44m:ue=\E[22;39;49m:tc=$TERM:"
 	;;
esac
%%%

The reasons for this fiddling like this with colors are:

(1) Reverse video that just reverses the colors tends to give a horrible
     combination of colors, since the best choices for foreground/background
     tend to be the worst choices when they are reversed.  Thus reverse
     video should normally be configured to not just reverse the colors,
     and there should be a way to control this.  The CSI [6-7]*x sequences
     and the CSI =*H/I provided a good way to do this.

(2) The colors selected for reverse video should not be undone by other
     color selections or by almost any escape sequence.  the CSI x
     sequences and CSI =F/G/H/I sequences work right for this.  They are
     not affected by the ANSI color escapes.  Of course, an ANSI color
     escape will change colors set by CSI x, but then on the next CSI m
     to normal or reverse (etc.) mode, the colors selected by CSI x will
     be restored.  Only a "hard" terminal reset should lose the settings
     of CSI x.  Hardware terminals are now rare, but ESC c is considered
     to be a hard reset and does undo CSI x.  You have to be careful not
     to use it.  cons25 may also have a "soft" reset but I don't remember
     what it is.  IIRC, ESC c is from vt100, and vt220 or vt320 had escape
     sequences for several levels of softer resets, some involving keeping
     color settings and others not.  Termcaps for vt100 mostly don't use
     ESC c since it really is a hard reset so it resets too much for most
     purposes.

(3) The ANSI color sequences (put in TERMCAP as above) don't work so well
     for this.  First you have to put them in TERMCAP and propagate this
     to many machines, instead of just writing a single setup sequence on
     the machine emulating a terminal.  Then they have to be written on
     ever change to/from reverse video/standout/underline.  I've noticed
     a couple of bugs involving the normal mode not being restored.
     Simpler CSI m sequences tend to restore the normal mode (if there
     is one) more reliably.

(4) To be complete, there would be a separate reverse color pair for
     every normal color pair (256 combinations even for only 8 colors),
     but configuring this would be too painful, and fixing 1 normal
     color pair and its corresponding reverse color pair works OK in
     practice.  Note that normal reverse video gives a different reverse
     pair for every normal pair, and this feature is lost by fixing the
     reverse pair.

(5) To be complete, standout, underline and blinking (all 2**N
     combinations of these) would be handled similarly, with a CSI x
     sequence to select the default colors used in all these modes.
     x86 displays have various deficiencies in being able to display
     all combinations of attributes simultaneously or at all, and syscons
     has too many hard-coded color choices for combinations that are
     not directly representable.  But configuring the general case would
     be too painful.  In the above, my TERMCAP color choices don't worry
     about this, so standout followed by underline would give the colors
     for just one of standout or underline depending on which order the
     escape sequences happen to be written in.  ORing together colors
     in their RGB or other representation would be worse.

>  It seems the terminfo library on some systems (OS X, Linux) may emit the
>  sequence \e[x to reset to default attributes. Apart from using the
>  zero-command, this escape sequence allows many more operations, such as
>  setting ANSI colors. I don't see this used anywhere, so this should be
>  sufficient for now.

Perhaps plain CSI x (\e[0x or \e[x) is used because it is a good or the
only "soft" reset.

Grepping in termcap.src didn't show many uses of CSI x.  Here it is for
pc3 (only the reset sequence):

% # The following is a version of the ibm-pc entry distributed with PC/IX,
% # (Interactive Systems' System 3 for the Big Blue), modified by Richard
% # McIntosh at UCB/CSM.  The :pt: and :uc: have been removed from the original,
% # (the former is untrue, and the latter failed under UCB/man); standout and
% # underline modes have been added.  Note: this entry describes the "native"
% # capabilities of the PC monochrome display, without ANY emulation; most
% # communications packages (but NOT PC/IX connect) do some kind of emulation.
% pc|ibmpc|ibm pc PC/IX:\
% 	...
% pc3|ibmpc3|IBM PC 386BSD Console:\
% 	...
% 	:op=\E[x:\
% 	...

cons25 is basically pc3 + sco cons.

Bruce


More information about the svn-src-all mailing list