Move function for opening links into terminal.py

This commit is contained in:
codesoap
2018-08-19 20:34:07 +02:00
parent d79e56fd20
commit cec9744702
2 changed files with 15 additions and 15 deletions

View File

@@ -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):
""" """

View File

@@ -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.