Skip to content

Commit

Permalink
Un-unicode output for Windows CMD
Browse files Browse the repository at this point in the history
minchinweb committed Apr 12, 2016
1 parent 73872d9 commit b985bc5
Showing 4 changed files with 16 additions and 4 deletions.
15 changes: 11 additions & 4 deletions green/output.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import platform
import sys
import termstyle
from unidecode import unidecode

global debug_level
debug_level = 0
@@ -144,14 +145,16 @@ class GreenStream(object):

def __init__(self, stream, override_appveyor=False, disable_windows=False):
self.stream = stream
self.disable_windows = disable_windows
self.override_appveyor = override_appveyor
# Ironically, AppVeyor doesn't support windows win32 system calls for
# colors, but it WILL interpret posix ansi escape codes!
on_windows = platform.system() == 'Windows'
on_appveyor = os.environ.get('APPVEYOR', False)
self.on_windows = platform.system() == 'Windows'
self.on_appveyor = os.environ.get('APPVEYOR', False)

if (override_appveyor
or ((on_windows and not on_appveyor)
and not disable_windows)): # pragma: no cover
or ((self.on_windows and not self.on_appveyor)
and not self.disable_windows)): # pragma: no cover
self.stream = wrap_stream(self.stream, None, None, None, True)
self.closed = False

@@ -167,6 +170,10 @@ def writeln(self, text=''):
def write(self, text):
if type(text) == bytes:
text = text.decode('utf-8')
if (self.override_appveyor
or ((self.on_windows and not self.on_appveyor)
and not self.disable_windows)): # pragma: no cover
text = unidecode(text)
self.stream.write(text)


3 changes: 3 additions & 0 deletions green/test/test_windows.py
Original file line number Diff line number Diff line change
@@ -23,3 +23,6 @@ def test_colorOutput(self):
self.assertTrue(issubclass(type(gs.stream),
colorama.ansitowin32.StreamWrapper))

def test_unicode_override(self):
pass

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
colorama
mock
python-termstyle
unidecode
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
dependencies = [
'colorama',
'python-termstyle',
'unidecode',
]
if sys.version_info[0] == 2:
dependencies.append('mock')

0 comments on commit b985bc5

Please sign in to comment.