diff --git a/rtv/__main__.py b/rtv/__main__.py index 074f255..9bd9ba7 100644 --- a/rtv/__main__.py +++ b/rtv/__main__.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals +from __future__ import print_function import os import sys @@ -40,8 +41,6 @@ def main(): # These ones get triggered even when capturing warnings is turned on warnings.simplefilter('ignore', ResourceWarning) #pylint:disable=E0602 - locale.setlocale(locale.LC_ALL, '') - # Set the terminal title if os.getenv('DISPLAY'): title = 'rtv {0}'.format(__version__) @@ -103,6 +102,15 @@ def main(): # Add an empty handler so the logger doesn't complain logging.root.addHandler(logging.NullHandler()) + # Make sure the locale is UTF-8 for unicode support + locale.setlocale(locale.LC_ALL, '') + encoding = locale.getlocale()[1] or locale.getdefaultlocale()[1] + if not encoding or encoding.lower() != 'utf-8': + text = ('System encoding was detected as (%s) instead of UTF-8' + ', falling back to ascii only mode' % encoding) + warnings.warn(text) + config['ascii'] = True + # Construct the reddit user agent user_agent = docs.AGENT.format(version=__version__) diff --git a/rtv/page.py b/rtv/page.py index 3dfc1f5..7569446 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -331,7 +331,7 @@ class Page(object): if os.getenv('DISPLAY'): title += ' - rtv {0}'.format(__version__) - sys.stdout.write('\x1b]2;{0}\x07'.format(title)) + sys.stdout.write('\x1b]2;{0}\x07'.format(self.term.clean(title))) sys.stdout.flush() if self.reddit.user is not None: