In progress.

This commit is contained in:
Michael Lazar
2015-04-29 22:31:24 -07:00
parent b573afeb2b
commit 49a9147ca6
5 changed files with 13 additions and 14 deletions

View File

@@ -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)

View File

@@ -1,4 +1,3 @@
import textwrap
import logging
import praw
@@ -164,7 +163,7 @@ class SubmissionContent(BaseContent):
elif index == -1:
data = self._submission_data
data['split_title'] = textwrap.wrap(data['title'], 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

View File

@@ -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

View File

@@ -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:

View File

@@ -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',