diff --git a/README.rst b/README.rst index 6b3cf6e..b53744c 100644 --- a/README.rst +++ b/README.rst @@ -134,6 +134,12 @@ Changelog This project adheres to `Semantic Versioning `_. +2.1.1 - 2016-05-10 +------------------ + +Fixed + * Printing box drawing characters on Windows from Python 2.6. + 2.1.0 - 2016-05-07 ------------------ diff --git a/appveyor.yml b/appveyor.yml index 68d680e..5b14160 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,3 +14,4 @@ test_script: tox -e lint,py35,py34,py33,py27,py26,py35x64,py34x64,py33x64,py27x6 on_finish: - appveyor PushArtifact test_example_test_windows_screenshot.png - appveyor PushArtifact test_windows_test_enable_disable.png + - appveyor PushArtifact test_windows_test_box_characters.png diff --git a/colorclass/__init__.py b/colorclass/__init__.py index f4ed862..4f67032 100644 --- a/colorclass/__init__.py +++ b/colorclass/__init__.py @@ -34,4 +34,4 @@ __author__ = '@Robpol86' __license__ = 'MIT' -__version__ = '2.1.0' +__version__ = '2.1.1' diff --git a/colorclass/windows.py b/colorclass/windows.py index 96283ae..8f69478 100644 --- a/colorclass/windows.py +++ b/colorclass/windows.py @@ -1,5 +1,7 @@ """Windows console screen buffer handlers.""" +from __future__ import print_function + import atexit import ctypes import re @@ -270,7 +272,7 @@ def write(self, p_str): continue if not RE_SPLIT.match(segment): # No color codes, print regular text. - self._original_stream.write(segment) + print(segment, file=self._original_stream, end='') self._original_stream.flush() continue for color_code in (int(c) for c in RE_NUMBER_SEARCH.findall(segment)[0].split(';')): diff --git a/setup.py b/setup.py index c8d5cb4..afce206 100755 --- a/setup.py +++ b/setup.py @@ -58,6 +58,6 @@ def readme(): name='colorclass', packages=['colorclass'], url='https://github.com/Robpol86/colorclass', - version='2.1.0', + version='2.1.1', zip_safe=True, ) diff --git a/tests/sub_box_green_win10.bmp b/tests/sub_box_green_win10.bmp new file mode 100644 index 0000000..485788e Binary files /dev/null and b/tests/sub_box_green_win10.bmp differ diff --git a/tests/sub_box_green_winxp.bmp b/tests/sub_box_green_winxp.bmp new file mode 100644 index 0000000..0823dd0 Binary files /dev/null and b/tests/sub_box_green_winxp.bmp differ diff --git a/tests/sub_box_sans_win10.bmp b/tests/sub_box_sans_win10.bmp new file mode 100644 index 0000000..48344b9 Binary files /dev/null and b/tests/sub_box_sans_win10.bmp differ diff --git a/tests/sub_box_sans_winxp.bmp b/tests/sub_box_sans_winxp.bmp new file mode 100644 index 0000000..8277d1e Binary files /dev/null and b/tests/sub_box_sans_winxp.bmp differ diff --git a/tests/test_windows.py b/tests/test_windows.py index 950d684..e96e4f9 100644 --- a/tests/test_windows.py +++ b/tests/test_windows.py @@ -359,3 +359,71 @@ def test_enable_disable(tmpdir): with RunNewConsole(command) as gen: screenshot_until_match(str(screenshot), 15, with_colors, 2, gen) screenshot_until_match(str(screenshot), 15, sans_colors, 2, gen) + + +@pytest.mark.skipif(str(not windows.IS_WINDOWS)) +def test_box_characters(tmpdir): + """Test for unicode errors with special characters. + + :param tmpdir: pytest fixture. + """ + screenshot = PROJECT_ROOT.join('test_windows_test_box_characters.png') + if screenshot.check(): + screenshot.remove() + script = tmpdir.join('script.py') + command = [sys.executable, str(script)] + + script.write(dedent("""\ + from __future__ import print_function + import os, time + from colorclass import Color, Windows + + Windows.enable(auto_colors=True) + chars = [ + '+', '-', '|', + b'\\xb3'.decode('ibm437'), + b'\\xb4'.decode('ibm437'), + b'\\xb9'.decode('ibm437'), + b'\\xba'.decode('ibm437'), + b'\\xbb'.decode('ibm437'), + b'\\xbc'.decode('ibm437'), + b'\\xbf'.decode('ibm437'), + b'\\xc0'.decode('ibm437'), + b'\\xc1'.decode('ibm437'), + b'\\xc2'.decode('ibm437'), + b'\\xc3'.decode('ibm437'), + b'\\xc4'.decode('ibm437'), + b'\\xc5'.decode('ibm437'), + b'\\xc8'.decode('ibm437'), + b'\\xc9'.decode('ibm437'), + b'\\xca'.decode('ibm437'), + b'\\xcb'.decode('ibm437'), + b'\\xcc'.decode('ibm437'), + b'\\xcd'.decode('ibm437'), + b'\\xce'.decode('ibm437'), + b'\\xd9'.decode('ibm437'), + b'\\xda'.decode('ibm437'), + ] + + for c in chars: + print(c, end='') + print() + for c in chars: + print(Color.green(c, auto=True), end='') + print() + + stop_after = time.time() + 20 + while not os.path.exists(r'%s') and time.time() < stop_after: + time.sleep(0.5) + """) % str(screenshot)) + + # Setup expected. + with_colors = [str(p) for p in PROJECT_ROOT.join('tests').listdir('sub_box_green_*.bmp')] + sans_colors = [str(p) for p in PROJECT_ROOT.join('tests').listdir('sub_box_sans_*.bmp')] + assert with_colors + assert sans_colors + + # Run. + with RunNewConsole(command) as gen: + screenshot_until_match(str(screenshot), 15, with_colors, 1, gen) + screenshot_until_match(str(screenshot), 15, sans_colors, 1, gen) diff --git a/tox.ini b/tox.ini index c60fbe4..6029a0a 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,7 @@ author = @Robpol86 license = MIT name = colorclass -version = 2.1.0 +version = 2.1.1 [tox] envlist = lint,py{34,27,26}