Move function for opening links into terminal.py
This commit is contained in:
@@ -159,7 +159,7 @@ class SubmissionPage(Page):
|
|||||||
if data['html']:
|
if data['html']:
|
||||||
links += self.get_links_in_html(data['html'])
|
links += self.get_links_in_html(data['html'])
|
||||||
if len(links) > 1:
|
if len(links) > 1:
|
||||||
self.prompt_user_and_open_selected_link(links)
|
self.term.prompt_user_and_open_selected_link(links)
|
||||||
elif 'url_full' in data and data['url_full']:
|
elif 'url_full' in data and data['url_full']:
|
||||||
self.term.open_link(data['url_full'])
|
self.term.open_link(data['url_full'])
|
||||||
else:
|
else:
|
||||||
@@ -175,20 +175,6 @@ class SubmissionPage(Page):
|
|||||||
links.append(link)
|
links.append(link)
|
||||||
return links
|
return links
|
||||||
|
|
||||||
def prompt_user_and_open_selected_link(self, links):
|
|
||||||
text = 'Open link:\n'
|
|
||||||
for i, link in enumerate(links[:9]):
|
|
||||||
capped_link_text = (link['text'] if len(link['text']) <= 20
|
|
||||||
else link['text'][:19] + '…')
|
|
||||||
text += '[{}] [{}]({})\n'.format(
|
|
||||||
i+1, capped_link_text, link['href'])
|
|
||||||
try:
|
|
||||||
choice = int(chr(self.term.show_notification(text)))
|
|
||||||
except ValueError:
|
|
||||||
return
|
|
||||||
if choice <= len(links):
|
|
||||||
self.term.open_link(links[choice - 1]['href'])
|
|
||||||
|
|
||||||
@SubmissionController.register(Command('SUBMISSION_OPEN_IN_PAGER'))
|
@SubmissionController.register(Command('SUBMISSION_OPEN_IN_PAGER'))
|
||||||
def open_pager(self):
|
def open_pager(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -354,6 +354,20 @@ class Terminal(object):
|
|||||||
|
|
||||||
return ch
|
return ch
|
||||||
|
|
||||||
|
def prompt_user_and_open_selected_link(self, links):
|
||||||
|
text = 'Open link:\n'
|
||||||
|
for i, link in enumerate(links[:9]):
|
||||||
|
capped_link_text = (link['text'] if len(link['text']) <= 20
|
||||||
|
else link['text'][:19] + '…')
|
||||||
|
text += '[{}] [{}]({})\n'.format(
|
||||||
|
i+1, capped_link_text, link['href'])
|
||||||
|
try:
|
||||||
|
choice = int(chr(self.show_notification(text)))
|
||||||
|
except ValueError:
|
||||||
|
return
|
||||||
|
if choice <= len(links):
|
||||||
|
self.open_link(links[choice - 1]['href'])
|
||||||
|
|
||||||
def open_link(self, url):
|
def open_link(self, url):
|
||||||
"""
|
"""
|
||||||
Open a media link using the definitions from the user's mailcap file.
|
Open a media link using the definitions from the user's mailcap file.
|
||||||
|
|||||||
Reference in New Issue
Block a user