From c3661c32c2340a85b8001667aa093fb5acc25784 Mon Sep 17 00:00:00 2001 From: Fathony Luthfillah Date: Tue, 11 Oct 2016 14:42:36 +0700 Subject: [PATCH] avoid ansi-escape replacing inside eclipse-pydev avoid conflicting colorama with the recommended eclipse plugin (ansi-escape) by pydev author that can enable color in pydev-console it's make both terminal & eclipse console can show color --- colorama/ansitowin32.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/colorama/ansitowin32.py b/colorama/ansitowin32.py index 8177d5b..275d441 100644 --- a/colorama/ansitowin32.py +++ b/colorama/ansitowin32.py @@ -8,6 +8,7 @@ from .win32 import windll, winapi_test +INSIDE_PYDEV = 'sitecustomize' in sys.modules #for avoid ansi-escape replacing when runngin inside eclipse-pydev winterm = None if windll is not None: winterm = WinTerm() @@ -164,11 +165,12 @@ def write_and_convert(self, text): ''' cursor = 0 text = self.convert_osc(text) - for match in self.ANSI_CSI_RE.finditer(text): - start, end = match.span() - self.write_plain_text(text, cursor, start) - self.convert_ansi(*match.groups()) - cursor = end + if not INSIDE_PYDEV: #avoid ansi-escape replacing when inside eclipse-pydev + for match in self.ANSI_CSI_RE.finditer(text): + start, end = match.span() + self.write_plain_text(text, cursor, start) + self.convert_ansi(*match.groups()) + cursor = end self.write_plain_text(text, cursor, len(text))