From owner-svn-src-all@FreeBSD.ORG Fri Nov 5 14:56:13 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0EC261065673; Fri, 5 Nov 2010 14:56:13 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail03.syd.optusnet.com.au (mail03.syd.optusnet.com.au [211.29.132.184]) by mx1.freebsd.org (Postfix) with ESMTP id 831818FC08; Fri, 5 Nov 2010 14:56:12 +0000 (UTC) Received: from c122-107-112-122.carlnfd1.nsw.optusnet.com.au (c122-107-112-122.carlnfd1.nsw.optusnet.com.au [122.107.112.122]) by mail03.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id oA5Eu8Cn016050 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 6 Nov 2010 01:56:10 +1100 Date: Sat, 6 Nov 2010 01:56:08 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Ed Schouten In-Reply-To: <201011050056.oA50uLk5078426@svn.freebsd.org> Message-ID: <20101105231811.V1254@besplex.bde.org> References: <201011050056.oA50uLk5078426@svn.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r214817 - head/sys/teken X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Nov 2010 14:56:13 -0000 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