Merge branch 'urlview' of https://github.com/msmith491/rtv into msmith491-urlview
This commit is contained in:
@@ -44,6 +44,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 = """
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user