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