Added urlview keybinding

1.  A shortcut of 'b' was used as the default binding for passing
comment body text to urlview (this is similar to the default of C-b in
the 'mutt' text email client)
2.  The `comment_urlview` SubmissionController function was added to
recieve the SUBMISSION_OPEN_IN_URLVIEWER keypress request.
3.  The `open_urlview` terminal function was added to handle the urlview
request.  It passes the comment body data to urlview via a Popen
process.
4.  A test case was added to ensure this new code path is executed
5.  Small formatting changes, mostly line length
This commit is contained in:
Matt Smith
2016-07-04 22:42:30 -07:00
committed by Matt Smith
parent fb837bafc7
commit 749ad11171
9 changed files with 343 additions and 9 deletions

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)