Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#151: Remove colorama init, Only use colorama on windows #152

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion halo/_utils.py
Original file line number Diff line number Diff line change
@@ -4,12 +4,23 @@
import codecs
import platform
import six
import sys

from colorama import init
from shutil import get_terminal_size
from termcolor import colored

init(autoreset=True)

wrap_stream_for_win = None

if sys.platform.startswith("win"):
try:
import colorama
except ImportError:
pass
else:
def wrap_stream_for_win(stream): # pylint: disable=function-redefined
return colorama.AnsiToWin32(stream, autoreset=True).stream


def is_supported():
3 changes: 3 additions & 0 deletions halo/halo.py
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@
is_supported,
is_text_type,
encode_utf_8_text,
wrap_stream_for_win,
)


@@ -87,6 +88,8 @@ def __init__(
self._interval = (
int(interval) if int(interval) > 0 else self._spinner["interval"]
)
if wrap_stream_for_win:
stream = wrap_stream_for_win(stream)
self._stream = stream

self.placement = placement
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
log_symbols>=0.0.14
spinners>=0.0.24
termcolor>=1.1.0
colorama>=0.3.9
colorama>=0.3.9; sys_platform == "win32"
six>=1.12.0
2 changes: 2 additions & 0 deletions tests/test_halo.py
Original file line number Diff line number Diff line change
@@ -95,6 +95,7 @@ def test_basic_spinner(self):
self.assertEqual(output[1], '{} foo'.format(frames[1]))
self.assertEqual(output[2], '{} foo'.format(frames[2]))

@unittest.skipIf(sys.platform.startswith("win"), "ANSI not supported on Windows")
def test_text_spinner_color(self):
"""Test basic spinner with available colors color (both spinner and text)
"""
@@ -590,6 +591,7 @@ def test_animation_setter(self):
spinner.animation = "marquee"
self.assertEqual("marquee", spinner.animation)

@unittest.skipIf(sys.platform.startswith("win"), "ANSI not supported on Windows")
def test_spinner_color(self):
"""Test ANSI escape characters are present
"""