cmd.exe on WIndows - problem with displaying some Unicode characters

Terry Reedy tjreedy at udel.edu
Mon Aug 4 15:43:49 EDT 2014


On 8/4/2014 1:22 PM, Wiktor wrote:
> On Tue, 5 Aug 2014 03:06:41 +1000, Chris Angelico wrote:
>
>> On Tue, Aug 5, 2014 at 2:48 AM, Wiktor <look at signature.invalid> wrote:
>>>    From colorama I just use one function - init(). Without this
>>> initialization all those ansii escape characters (used by colorama itself,
>>> but also by termcolor.colored()) don't work in cmd.exe. At least I couldn't
>>> make it work.
>>
>> I dug into colorama's source code, and it seems that "just one
>> function" is a little dismissive :) When you call colorama's init(),
>> it replaces stdout with a wrapper that parses ANSI sequences and turns
>> them into API calls. So, yeah, without that anything that outputs ANSI
>> sequences isn't going to work.
>
>    Maybe I didn't write it clear. :-) What I meant was, that even though I
> don't use any other functions from colorama (I color all the strings with
> termcolor) - I still have to use init() function from colorama.
>    termcolor doesn't want to work alone, even though its described as OS
> independent.

Termcolor says "ANSI Color formatting for output in terminal."
https://pypi.python.org/pypi/termcolor/1.1.0

It is OS-independent but depends on support of standard ANSI screen 
command codes. Microsoft removed that support from cmd.exe. If you look 
at the Terminal properties box on the page above, the only thing 
termcolor can do on Windows, by itself, is reversed text.  Colorama.init 
adds back (at least some of) the ANSI to API translation omitted from 
cmd.exe.

> I guess it works fine on Linux terminal without init()

Because linux terminals translate ANSI to whatever api calls are needed.

> function from colorama. In cmd.exe I need colorama just for this.

-- 
Terry Jan Reedy




More information about the Python-list mailing list