[PATCH] ui.prompt(): let overridden write() method do it's job. Fix for color on win32.

Idan Kamara idankk86 at gmail.com
Mon Aug 1 11:15:48 CDT 2011


On Mon, Aug 1, 2011 at 12:22 AM, Andrei Vermel <andrei.vermel at gmail.com>
wrote:
>
> On 01-Aug-11 12:23 AM, Mads Kiilerich wrote:
>>
>> Andrei Vermel wrote, On 07/31/2011 05:55 PM:
>>>
>>> # HG changeset patch
>>> # Parent b192d1dc6a848d08b757dd0f6fb2f4416acc170f
>>> # User Andrei Vermel <avermel at mail.ru>
>>> # Date 1312127463 -14400
>>>
>>> ui.prompt(): let overridden write() method do it's job. Fix for color on
win32.
>>>
>>
>> Will this also fix http://mercurial.selenic.com/bts/issue2887 ?
>>
>>> diff --git a/mercurial/ui.py b/mercurial/ui.py
>>> --- a/mercurial/ui.py
>>> +++ b/mercurial/ui.py
>>> @@ -540,7 +540,7 @@
>>>         # instead of trying to emulate raw_input, swap our in/out
>>>         # with sys.stdin/out
>>>         old = sys.stdout, sys.stdin
>>> -        sys.stdout, sys.stdin = self.fout, self.fin
>>> +        sys.stdout, sys.stdin = self, self.fin
>>
>> Wouw. _That_ is duck typing. I don't think the ui class itself was
intended to implement the file protocol, so relying on it might be a bit
fragile.
>>
>
> On the other hand what else could raw_input() possibly use apart from the
write method ?
> I believe it is pretty much safe.

Not much, except checking that sys.stdout derives from file, and
that isatty(fileno(sys.stdout)) is true, which will fail now.

http://hg.python.org/cpython/file/b9a95ce2692c/Python/bltinmodule.c#l2029

So while this fixes the color issue on Windows, I guess it disables readline
functionality on *nix.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20110801/804e632c/attachment.html>


More information about the Mercurial-devel mailing list