New submission from Dave Rove <daver1...@bobmail.info>:

The correct handling of ANSI escape codes by the print() function may or may 
not be enabled in the Windows 10 command prompt window, depending on previous 
system calls. The following is quite repeatable. Comment-out the apparently 
meaningless os.system("") line and ANSI codes do not work, but leave that line 
in and ANSI codes DO work:

    import os
    os.system("") # Comment this out to disable ANSI codes
    ansi_red = "\x1b[31m"
    ansi_normal = "\x1b[0m"
    print(ansi_red + "This is red!" + ansi_normal)

To be consistent with Python on Linux and Mac, I believe that ANSI codes should 
be permanently enabled in Windows 10 rather than removed. ANSI code handling 
was present from the start of Windows 10, so it's reasonable to presume that 
it's now a permanent feature of the Windows command prompt window. Either way, 
the inconsistency of the handling should be fixed.

To emphasize that ANSI codes ARE a feature of the command prompt, comment out 
that line to disable the ANSI codes in print(), but redirect the output to a 
text file. Then display that file at the command prompt. The ANSI codes then 
work correctly. 

    python myansi.py > myansi.txt
    type myansi.txt

----------
components: Windows
messages: 365458
nosy: daverove, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: Inconsistent ANSI escape code handling on Windows 10
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40134>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to