On Mon, Nov 29, 2010 at 06:42:53PM +0100, Alexander Matthes wrote:
> It's great to know, that somebody has interests in my tool. I tried
> to translate it to English completely and fixed the warnings,

Cool!

> Which thing except the coloring in the terminal begins with \e[? O_o

For example, cursor movement commands if someone tries to process the output
from a full-screen program.  Trying to understand those would be a long
story and for several reasons is not really plausible, but we need to at
least properly ignore those rather than misinterpret them as colors.

In proper line based programs in the wild, I've seen the following codes:
* \e[ ... J  clear screen (usually 2 -- whole screen)
* \e[ ... K  clear line (0 -- after cursor, 1 -- to cursor, 2 -- whole line)
* \e[ ... D  move cursor left (abused as backspace/\r)
* \e[ ... C  move cursor right (used for compressing spaces)

Of course, assuming a strict hardcopy terminal, you can't edit the line, so
\e[K and \e[D could be left unimplemented.  It can be argued none of these
make sense in a colored log, so just ignoring them is a valid strategy -- as
long as they are actually parsed and ignored.

> I don't get your example, Adam. What exactly is the bug?

A SGR ("set graphic rendition", \e[ ... m) code is a series of commands. 
You parse only the following cases:
\e[Xm
\e[3Xm
\e[4Xm
\e[X;3Ym
\e[X;4Ym
with X and Y being single digits.

The proper perl regexp is: \e\[\d*[;\d*]*m

There may be any number of commands -- popular sequences include for example
\e[0;44;33;1m which gives yellow-on-blue.

Any order is allowed, although of course later commands may render earlier
ones moot.  An example is \e[2;37;0m -- popular through copy&paste among
people who use color codes without understanding the syntax.  It first makes
the text dim, then makes it white/gray, then finally resets it making the
two first commands pointless.

The commands can be any unsigned integers.  In particular, they can be
bigger numbers which happen to start with 3 -- there's none of these among
old-style values but they may be present in extensions.

The integers may have leading zeroes.  Both curses and ls used to have 00 as
the reset command, for example.

An empty command is explicitely allowed by the standard, meaning "0".  This
is often used in \[m although I've seen \e[;31m and the like as well.


This was about the syntax.  About coverage of commands, popular ones which
you lack are:
* 39  reset foreground color
* 49  reset background color
* 21  turn off bold/brightness
* 7   inverse

The rest are nice to have, although support for rarer commands is spotty
among real terminals as well, so they're not that important.

There was a multitude of extensions in the past, but they seem to have died
off, save for xterm-256 colors which are gaining traction.


Hope this helps,
-- 
1KB             // Microsoft corollary to Hanlon's razor:
                //      Never attribute to stupidity what can be
                //      adequately explained by malice.

Attachment: signature.asc
Description: Digital signature

Reply via email to