From cec9744702099f8ca8a72e3901da76e077bdfa9c Mon Sep 17 00:00:00 2001 From: codesoap Date: Sun, 19 Aug 2018 20:34:07 +0200 Subject: [PATCH] Move function for opening links into terminal.py --- rtv/submission_page.py | 16 +--------------- rtv/terminal.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/rtv/submission_page.py b/rtv/submission_page.py index 9db6653..1ab9fef 100644 --- a/rtv/submission_page.py +++ b/rtv/submission_page.py @@ -159,7 +159,7 @@ class SubmissionPage(Page): if data['html']: links += self.get_links_in_html(data['html']) 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']: self.term.open_link(data['url_full']) else: @@ -175,20 +175,6 @@ class SubmissionPage(Page): links.append(link) 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')) def open_pager(self): """ diff --git a/rtv/terminal.py b/rtv/terminal.py index 94cd7a7..1f714a4 100644 --- a/rtv/terminal.py +++ b/rtv/terminal.py @@ -354,6 +354,20 @@ class Terminal(object): 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): """ Open a media link using the definitions from the user's mailcap file.