[PATCH] color: use ui.formatted() to test TTYness, not sys.stdout.isatty()

Thomas Arendsen Hein thomas at intevation.de
Tue Jun 21 10:44:54 CDT 2011


* Matt Mackall <mpm at selenic.com> [20110504 22:24]:
> On Wed, 2011-05-04 at 10:16 -0700, Danek Duvall wrote:
> > Like I said, it comes from the terminfo entry for your terminal.  See the
> > output of "infocmp $TERM", and it's right there, in sgr0.  It has nothing
> > to do with python or (n)curses; it's a fundamental problem with the way
> > that less tries to figure out which control sequences are related to color
> > and which aren't.  You'll see exactly the same thing with any other program
> > that emits terminfo-based color whose output you pipe through less.
> > Unfortunately, I don't know of any program that does that -- colorized ls
> > uses ansi color sequences, and all other programs I use that use color do
> > it with terminfo, but none of them are usefully paged.
> 
> Grumble. Yes, the less docs say that -R only understands ANSI codes.
> 
> So, we can:
> 
> 1) only support ANSI
> 2) force ANSI mode when using the pager
> 3) disable color when using the pager
> 
> 
> Relatedly, less is generally not configured with -R out of the box,
> which means you either need to turn color off or turn -R on to get a
> working setup. I'd rather we had to turn color support on in pager and
> documented it, eg:
> 
>  To get color support in pager, set:
> 
>  [pager]
>  color = true
>  pager = less -R  # handle ANSI color codes

This was reported in http://mercurial.selenic.com/bts/issue2792 and
I just commented there that I would prefer this latest suggestion
(turn off color in pager by default, enable it explicitly and
document the need for color.mode=ansi when using less -R)

Regards,
Thomas

-- 
thomas at intevation.de - http://intevation.de/~thomas/ - OpenPGP key: 0x5816791A
Intevation GmbH, Neuer Graben 17, 49074 Osnabrueck - AG Osnabrueck, HR B 18998
Geschaeftsfuehrer: Frank Koormann, Bernhard Reiter, Dr. Jan-Oliver Wagner


More information about the Mercurial-devel mailing list