diff --git a/rtv/__main__.py b/rtv/__main__.py index 9cc78b0..5322afd 100644 --- a/rtv/__main__.py +++ b/rtv/__main__.py @@ -59,8 +59,7 @@ def command_line(): parser.add_argument('-s', dest='subreddit', help='subreddit name') parser.add_argument('-l', dest='link', help='full link to a submission') - parser.add_argument('--unicode', action='store_true', - help='enable unicode (experimental)') + parser.add_argument('--unicode', help='enable unicode (experimental)') parser.add_argument('--log', metavar='FILE', action='store', help='Log HTTP requests') @@ -95,7 +94,7 @@ def main(): if getattr(args, key, None) is None: setattr(args, key, val) - config.unicode = args.unicode + config.unicode = False if args.unicode is None else args.unicode # Squelch SSL warnings for Ubuntu logging.captureWarnings(True) diff --git a/rtv/content.py b/rtv/content.py index c6bbd8b..1baaa49 100644 --- a/rtv/content.py +++ b/rtv/content.py @@ -1,4 +1,3 @@ -import textwrap import logging import praw @@ -164,8 +163,8 @@ class SubmissionContent(BaseContent): elif index == -1: data = self._submission_data - data['split_title'] = textwrap.wrap(data['title'], width=n_cols -2) - data['split_text'] = wrap_text(data['text'], width=n_cols - 2) + data['split_title'] = wrap_text(data['title'], width=n_cols-2) + data['split_text'] = wrap_text(data['text'], width=n_cols-2) data['n_rows'] = len(data['split_title'] + data['split_text']) + 5 data['offset'] = 0 @@ -326,7 +325,7 @@ class SubredditContent(BaseContent): # Modifies the original dict, faster than copying data = self._submission_data[index] - data['split_title'] = textwrap.wrap(data['title'], width=n_cols) + data['split_title'] = wrap_text(data['title'], width=n_cols) data['n_rows'] = len(data['split_title']) + 3 data['offset'] = 0 diff --git a/rtv/helpers.py b/rtv/helpers.py index 582901a..44b99d3 100644 --- a/rtv/helpers.py +++ b/rtv/helpers.py @@ -1,17 +1,18 @@ import sys import os -import textwrap import subprocess from datetime import datetime from tempfile import NamedTemporaryFile +# kitchen solves deficiencies in textwrap's handling of unicode characters +from kitchen.text.display import wrap + from . import config from .exceptions import ProgramError __all__ = ['open_browser', 'clean', 'wrap_text', 'strip_textpad', 'strip_subreddit_url', 'humanize_timestamp', 'open_editor'] - def open_editor(data=''): """ Open a temporary file using the system's default editor. @@ -74,11 +75,10 @@ def clean(string): If utf-8 is passed in, addnstr will treat each 'byte' as a single character. """ - encoding = 'utf-8' if config.unicode else 'ascii' - string = string.encode(encoding, 'replace') + if not config.unicode: + string = string.encode('ascii', 'replace') return string - def wrap_text(text, width): """ Wrap text paragraphs to the given character width while preserving newlines. @@ -87,7 +87,7 @@ def wrap_text(text, width): for paragraph in text.splitlines(): # Wrap returns an empty list when paragraph is a newline. In order to # preserve newlines we substitute a list containing an empty string. - lines = textwrap.wrap(paragraph, width=width) or [''] + lines = wrap(paragraph, width=width) or [''] out.extend(lines) return out diff --git a/rtv/page.py b/rtv/page.py index f38ee7b..c091137 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -470,6 +470,7 @@ class BasePage(object): self._header_window.bkgd(' ', attr) sub_name = self.content.name.replace('/r/front', 'Front Page ') + sub_name = 'blank' self._header_window.addnstr(0, 0, clean(sub_name), n_cols - 1) if self.reddit.user is not None: diff --git a/setup.py b/setup.py index 4f087e2..6cc3c77 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ setup( keywords='reddit terminal praw curses', packages=['rtv'], include_package_data=True, - install_requires=['praw>=2.1.6', 'six', 'requests'], + install_requires=['praw>=2.1.6', 'six', 'requests', 'kitchen'], entry_points={'console_scripts': ['rtv=rtv.__main__:main']}, classifiers=[ 'Intended Audience :: End Users/Desktop',