changeset 36683:e39953fdd924

profile: colorize output on Windows Previously, the ANSI codes were printed to the screen, throwing off the alignment. We could probably do this unconditionally, but it's kind of a hack, so I figured I'd limit the scope.
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 03 Mar 2018 00:35:59 -0500
parents 68328202f270
children 5f41e3418407
files mercurial/profiling.py
diffstat 1 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/profiling.py	Sat Mar 03 19:02:50 2018 -0500
+++ b/mercurial/profiling.py	Sat Mar 03 00:35:59 2018 -0500
@@ -14,6 +14,7 @@
     encoding,
     error,
     extensions,
+    pycompat,
     util,
 )
 
@@ -200,6 +201,17 @@
             elif self._output:
                 path = self._ui.expandpath(self._output)
                 self._fp = open(path, 'wb')
+            elif pycompat.iswindows:
+                # parse escape sequence by win32print()
+                class uifp(object):
+                    def __init__(self, ui):
+                        self._ui = ui
+                    def write(self, data):
+                        self._ui.write_err(data)
+                    def flush(self):
+                        self._ui.flush()
+                self._fpdoclose = False
+                self._fp = uifp(self._ui)
             else:
                 self._fpdoclose = False
                 self._fp = self._ui.ferr