Merge remote-tracking branch 'origin/master' into more_listings

This commit is contained in:
woorst
2016-07-15 16:54:21 -05:00
18 changed files with 3997 additions and 23 deletions

View File

@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
__version__ = '1.9.1'
__version__ = '1.10.0'

View File

@@ -128,10 +128,11 @@ class Content(object):
displayed through the terminal.
Definitions:
permalink - Full URL to the submission comments.
url_full - Link that the submission points to.
url - URL that is displayed on the subreddit page, may be
"selfpost" or "x-post" or a link.
permalink - URL to the reddit page with submission comments.
url_full - URL that the submission points to.
url - URL that will be displayed on the subreddit page, may be
"selfpost", "x-post submission", "x-post subreddit", or an
external link.
"""
reddit_link = re.compile(
@@ -147,8 +148,7 @@ class Content(object):
data['text'] = sub.selftext
data['created'] = cls.humanize_timestamp(sub.created_utc)
data['comments'] = '{0} comments'.format(sub.num_comments)
data['score'] = '{0} pts'.format(
'-' if sub.hide_score else sub.score)
data['score'] = '{0} pts'.format('-' if sub.hide_score else sub.score)
data['author'] = name
data['permalink'] = sub.permalink
data['subreddit'] = six.text_type(sub.subreddit)
@@ -159,6 +159,7 @@ class Content(object):
data['nsfw'] = sub.over_18
data['stickied'] = sub.stickied
data['hidden'] = False
data['xpost_subreddit'] = None
data['index'] = None # This is filled in later by the method caller
if sub.url.split('/r/')[-1] == sub.permalink.split('/r/')[-1]:
@@ -167,8 +168,13 @@ class Content(object):
elif reddit_link.match(sub.url):
# Strip the subreddit name from the permalink to avoid having
# submission.subreddit.url make a separate API call
data['url'] = 'self.{0}'.format(sub.url.split('/')[4])
data['url_type'] = 'x-post'
url_parts = sub.url.split('/')
data['xpost_subreddit'] = url_parts[4]
data['url'] = 'self.{0}'.format(url_parts[4])
if 'comments' in url_parts:
data['url_type'] = 'x-post submission'
else:
data['url_type'] = 'x-post subreddit'
else:
data['url'] = sub.url
data['url_type'] = 'external'

View File

@@ -45,6 +45,7 @@ HELP = """
`h` or `LEFT` : Return to subreddit mode
`l` or `RIGHT` : Open the selected comment in a new window
`SPACE` : Fold the selected comment, or load additional comments
`b` : Display URLs with urlview
"""
COMMENT_FILE = """

View File

@@ -280,7 +280,9 @@ class Page(object):
ch, attr = str(' '), curses.A_REVERSE | curses.A_BOLD | Color.CYAN
window.bkgd(ch, attr)
sub_name = self.content.name.replace('/r/front', 'Front Page')
sub_name = self.content.name
sub_name = sub_name.replace('/r/front', 'Front Page')
sub_name = sub_name.replace('/r/me', 'My Submissions')
self.term.add_line(window, sub_name, 0, 0)
# Set the terminal title
@@ -289,7 +291,7 @@ class Page(object):
else:
title = sub_name
title = title + ' - rtv {0}'.format(__version__)
title += ' - rtv {0}'.format(__version__)
sys.stdout.write('\x1b]2;{0}\x07'.format(title))
sys.stdout.flush()

View File

@@ -112,6 +112,7 @@ SUBMISSION_OPEN_IN_BROWSER = o, <LF>, <KEY_ENTER>
SUBMISSION_POST = c
SUBMISSION_EXIT = h, <KEY_LEFT>
SUBMISSION_OPEN_IN_PAGER = l, <KEY_RIGHT>
SUBMISSION_OPEN_IN_URLVIEWER = b
; Subreddit page
SUBREDDIT_SEARCH = f

View File

@@ -35,11 +35,11 @@ class SubmissionPage(Page):
current_index = self.nav.absolute_index
self.content.toggle(current_index)
# This logic handles a display edge case after a comment toggle. We want
# to make sure that when we re-draw the page, the cursor stays at its
# current absolute position on the screen. In order to do this, apply
# a fixed offset if, while inverted, we either try to hide the bottom
# comment or toggle any of the middle comments.
# This logic handles a display edge case after a comment toggle. We
# want to make sure that when we re-draw the page, the cursor stays at
# its current absolute position on the screen. In order to do this,
# apply a fixed offset if, while inverted, we either try to hide the
# bottom comment or toggle any of the middle comments.
if self.nav.inverted:
data = self.content.get(current_index)
if data['hidden'] or self.nav.cursor_index != 0:
@@ -147,6 +147,15 @@ class SubmissionPage(Page):
else:
self.term.flash()
@SubmissionController.register(Command('SUBMISSION_OPEN_IN_URLVIEWER'))
def comment_urlview(self):
data = self.content.get(self.nav.absolute_index)
comment = data.get('body', '')
if comment:
self.term.open_urlview(comment)
else:
self.term.flash()
def _draw_item(self, win, data, inverted):
if data['type'] == 'MoreComments':
@@ -219,7 +228,8 @@ class SubmissionPage(Page):
n_cols -= 1
self.term.add_line(win, '{body}'.format(**data), 0, 1)
self.term.add_line(win, ' [{count}]'.format(**data), attr=curses.A_BOLD)
self.term.add_line(
win, ' [{count}]'.format(**data), attr=curses.A_BOLD)
attr = Color.get_level(data['level'])
self.term.addch(win, 0, 0, self.term.vline, attr)

View File

@@ -101,7 +101,9 @@ class SubredditPage(Page):
data = self.content.get(self.nav.absolute_index)
if data['url_type'] == 'selfpost':
self.open_submission()
elif data['url_type'] == 'x-post':
elif data['url_type'] == 'x-post subreddit':
self.refresh_content(order='ignore', name=data['xpost_subreddit'])
elif data['url_type'] == 'x-post submission':
self.open_submission(url=data['url_full'])
self.config.history.add(data['url_full'])
else:

View File

@@ -349,7 +349,8 @@ class Terminal(object):
'Browser exited with status=%s' % code)
time.sleep(0.01)
else:
raise exceptions.BrowserError('Timeout opening browser')
raise exceptions.BrowserError(
'Timeout opening browser')
finally:
# Can't check the loader exception because the oauth module
# supersedes this loader and we need to always kill the
@@ -438,6 +439,20 @@ class Terminal(object):
else:
_logger.info('File deleted: %s', filepath)
def open_urlview(self, data):
urlview = os.getenv('RTV_URLVIEWER') or 'urlview'
try:
with self.suspend():
p = subprocess.Popen([urlview],
stdin=subprocess.PIPE)
try:
p.communicate(input=six.b(data))
except KeyboardInterrupt:
p.terminate()
except OSError:
self.show_notification(
'Could not open urls with {}'.format(urlview))
def text_input(self, window, allow_resize=False):
"""
Transform a window into a text box that will accept user input and loop
@@ -574,4 +589,4 @@ class Terminal(object):
break
out = '\n'.join(stack)
return out
return out