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

update check for Unicode support #144

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
34 changes: 28 additions & 6 deletions halo/_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# -*- coding: utf-8 -*-
"""Utilities for Halo library.
"""
import builtins
import codecs
import platform
import locale
import os
import sys
import six
try:
from shutil import get_terminal_size
Expand All @@ -23,14 +26,33 @@ def is_supported():
boolean
Whether operating system supports main symbols or not
"""
possible_encodings = (
# the current, possibly redirected stdout
(sys.stdout.encoding if getattr(builtins, '__IPYTHON__', False) else None),
# the original stdout at the time python started
sys.__stdout__.encoding,
(os.device_encoding(sys.__stdout__.fileno()) if sys.__stdout__.isatty() else None),
locale.getpreferredencoding(),
locale.getpreferredencoding(False),
)

for encoding in possible_encodings:
try:
current_encoding = codecs.lookup(encoding)
except:
continue
else:
break
else:
return False

os_arch = platform.system()

if os_arch != 'Windows':
try:
current_encoding.encode('\u280b')
except UnicodeError:
return False
else:
return True

return False


def get_environment():
"""Get the environment in which halo is running
Expand Down