Merge branch 'yank_links_prompt' of https://github.com/woorst/rtv into woorst-yank_links_prompt
This commit is contained in:
@@ -149,7 +149,7 @@ class Content(object):
|
||||
data['type'] = 'Comment'
|
||||
data['level'] = comment.nested_level
|
||||
data['body'] = comment.body
|
||||
data['html'] = comment.body_html
|
||||
data['html'] = comment.body_html or ''
|
||||
data['created'] = cls.humanize_timestamp(comment.created_utc)
|
||||
data['score'] = '{0} pts'.format(
|
||||
'-' if comment.score_hidden else comment.score)
|
||||
|
||||
@@ -67,7 +67,7 @@ https://github.com/michael-lazar/rtv
|
||||
SPACE : Hide a submission, or fold/expand the selected comment tree
|
||||
b : Display urls with urlview
|
||||
y : Copy submission permalink to clipboard
|
||||
Y : Copy submission link to clipboard
|
||||
Y : Copy submission or comment urls to clipboard
|
||||
F2 : Cycle to previous theme
|
||||
F3 : Cycle to next theme
|
||||
|
||||
|
||||
31
rtv/page.py
31
rtv/page.py
@@ -304,6 +304,29 @@ class Page(object):
|
||||
message = 'New Messages' if inbox > 0 else 'No New Messages'
|
||||
self.term.show_notification(message)
|
||||
|
||||
def prompt_and_select_link(self):
|
||||
"""
|
||||
Prompt the user to select a link from a list to open.
|
||||
|
||||
Return the link that was selected, or ``None`` if no link was selected.
|
||||
"""
|
||||
data = self.get_selected_item()
|
||||
url_full = data.get('url_full')
|
||||
if url_full and url_full != data['permalink']:
|
||||
# The item is a link-only submission that won't contain text
|
||||
link = data['url_full']
|
||||
else:
|
||||
extracted_links = self.content.extract_links(data.get('html', ''))
|
||||
if not extracted_links:
|
||||
# Only one selection to choose from, so just pick it
|
||||
link = data.get('permalink')
|
||||
else:
|
||||
# Let the user decide which link to open
|
||||
links = [{'text': 'Permalink', 'href': data['permalink']}]
|
||||
links += extracted_links
|
||||
link = self.term.prompt_user_to_select_link(links)
|
||||
return link
|
||||
|
||||
@PageController.register(Command('COPY_PERMALINK'))
|
||||
def copy_permalink(self):
|
||||
"""
|
||||
@@ -329,11 +352,9 @@ class Page(object):
|
||||
@PageController.register(Command('COPY_URL'))
|
||||
def copy_url(self):
|
||||
"""
|
||||
Copies submission url to OS clipboard
|
||||
Copies link to OS clipboard
|
||||
"""
|
||||
|
||||
data = self.get_selected_item()
|
||||
url = data.get('url_full')
|
||||
url = self.prompt_and_select_link()
|
||||
if url is None:
|
||||
self.term.flash()
|
||||
return
|
||||
@@ -346,7 +367,7 @@ class Page(object):
|
||||
'Failed to copy url: {0}'.format(e))
|
||||
else:
|
||||
self.term.show_notification(
|
||||
'Copied url to clipboard', timeout=1)
|
||||
['Copied to clipboard:', url], timeout=1)
|
||||
|
||||
def clear_input_queue(self):
|
||||
"""
|
||||
|
||||
@@ -143,36 +143,19 @@ class SubmissionPage(Page):
|
||||
If there is more than one link contained in the item, prompt the user
|
||||
to choose which link to open.
|
||||
"""
|
||||
data = self.get_selected_item()
|
||||
if data['type'] == 'Submission':
|
||||
opened_link = self.prompt_and_open_link(data)
|
||||
if opened_link is not None:
|
||||
self.config.history.add(opened_link)
|
||||
elif data['type'] == 'Comment' and data['permalink']:
|
||||
self.prompt_and_open_link(data)
|
||||
link = self.prompt_and_select_link()
|
||||
if link:
|
||||
data = self.get_selected_item()
|
||||
if data['type'] == 'Submission':
|
||||
self.config.history.add(link)
|
||||
self.term.open_link(link)
|
||||
elif data['type'] == 'Comment' and data['permalink']:
|
||||
self.term.open_link(link)
|
||||
else:
|
||||
self.term.flash()
|
||||
else:
|
||||
self.term.flash()
|
||||
|
||||
def prompt_and_open_link(self, data):
|
||||
url_full = data.get('url_full')
|
||||
if url_full and url_full != data['permalink']:
|
||||
# The item is a link-only submission that won't contain text
|
||||
link = data['url_full']
|
||||
else:
|
||||
extracted_links = self.content.extract_links(data['html'])
|
||||
if not extracted_links:
|
||||
# Only one selection to choose from, so just pick it
|
||||
link = data['permalink']
|
||||
else:
|
||||
# Let the user decide which link to open
|
||||
links = [{'text': 'Permalink', 'href': data['permalink']}]
|
||||
links += extracted_links
|
||||
link = self.term.prompt_user_to_select_link(links)
|
||||
|
||||
if link is not None:
|
||||
self.term.open_link(link)
|
||||
return link
|
||||
|
||||
@SubmissionController.register(Command('SUBMISSION_OPEN_IN_PAGER'))
|
||||
def open_pager(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user