From 9f7e6a1bfb7661b1d4766e9b75d3d772b351f463 Mon Sep 17 00:00:00 2001 From: Thomas Nagy Date: Fri, 14 Mar 2014 21:47:19 +0100 Subject: [PATCH] Revert "it turns out that writeconsole in ansiterm.py is not needed" This reverts commit 3deaeb241a9321021f79815200171eb37ede98ef. Signed-off-by: Thomas Nagy --- waflib/ansiterm.py | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/waflib/ansiterm.py b/waflib/ansiterm.py index b6f389f0..f56967e3 100644 --- a/waflib/ansiterm.py +++ b/waflib/ansiterm.py @@ -82,11 +82,7 @@ else: class AnsiTerm(object): """ - Wrapper for cmd.exe stdio, to support vt100 escape codes - - Notes: - - CR printed when the cursor is at EOL will do nothing, - whereas on UNIX, it will go to the line beginning. + emulate a vt100 terminal in cmd.exe """ def __init__(self, s): self.stream = s @@ -271,7 +267,7 @@ else: if cmd_func: cmd_func(self, param) else: - self.stream.write(txt) + self.writeconsole(txt) else: # no support for colors in the console, just output the text: # eclipse or msys may be able to interpret the escape sequences @@ -279,11 +275,33 @@ else: finally: wlock.release() + def writeconsole(self, txt): + chars_written = c_int() + writeconsole = windll.kernel32.WriteConsoleA + if isinstance(txt, _type): + writeconsole = windll.kernel32.WriteConsoleW + + # MSDN says that there is a shared buffer of 64 KB for the console + # writes. Attempt to not get ERROR_NOT_ENOUGH_MEMORY, see waf issue #746 + done = 0 + todo = len(txt) + chunk = 32<<10 + while todo != 0: + doing = min(chunk, todo) + buf = txt[done:done+doing] + r = writeconsole(self.hconsole, buf, doing, byref(chars_written), None) + if r == 0: + chunk >>= 1 + continue + done += doing + todo -= doing + + def fileno(self): return self.stream.fileno() def flush(self): - return self.stream.flush() + pass def isatty(self): return self._isatty