From 6328407c32a78af79948471c827747ccba016686 Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Fri, 5 Aug 2016 17:56:36 -0700 Subject: [PATCH] Got the prompt working from submissions / subscriptions. --- CONTROLS.rst | 2 +- rtv/docs.py | 2 +- rtv/submission.py | 10 ++++++++++ rtv/subreddit.py | 22 ++++++++++++++++------ rtv/subscription.py | 13 +++++++++++-- rtv/templates/rtv.cfg | 2 +- tests/test_subscription.py | 6 +++--- 7 files changed, 43 insertions(+), 14 deletions(-) diff --git a/CONTROLS.rst b/CONTROLS.rst index 289765f..8be7f9e 100644 --- a/CONTROLS.rst +++ b/CONTROLS.rst @@ -14,6 +14,7 @@ Basic Commands :``1-5``: Toggle post order (*hot*, *top*, *rising*, *new*, *controversial*) :``r`` or ``F5``: Refresh page content :``u``: Log in or switch accounts +:``/``: Open a prompt to switch subreddits :``?``: Show the help screen :``q``/``Q``: Quit/Force quit @@ -43,7 +44,6 @@ In subreddit mode you can browse through the top submissions on either the front :``l`` or ``►``: Enter the selected submission :``o`` or ``ENTER``: Open the submission link with your web browser -:``/``: Open a prompt to switch subreddits :``f``: Open a prompt to search the current subreddit :``p``: Toggle between the front page and the last visited subreddit diff --git a/rtv/docs.py b/rtv/docs.py index f027d3f..79513f9 100644 --- a/rtv/docs.py +++ b/rtv/docs.py @@ -29,6 +29,7 @@ https://github.com/michael-lazar/rtv 1-5 : Toggle post order r or F5 : Refresh page content u : Log in or switch accounts + / : Open a prompt to switch subreddits ? : Show the help screen q/Q : Quit/Force quit @@ -45,7 +46,6 @@ https://github.com/michael-lazar/rtv [Subreddit Commands] l or ► : Enter the selected submission o or ENTER : Open the submission link with your web browser - / : Open a prompt to switch subreddits f : Open a prompt to search the current subreddit p : Return to the front page diff --git a/rtv/submission.py b/rtv/submission.py index d557d1b..18f0be3 100644 --- a/rtv/submission.py +++ b/rtv/submission.py @@ -27,6 +27,7 @@ class SubmissionPage(Page): self.content = SubmissionContent(submission, term.loader) # Start at the submission post, which is indexed as -1 self.nav = Navigator(self.content.get, page_index=-1) + self.subreddit_name = None @SubmissionController.register(Command('SUBMISSION_TOGGLE_COMMENT')) def toggle_comment(self): @@ -67,6 +68,15 @@ class SubmissionPage(Page): if not self.term.loader.exception: self.nav = Navigator(self.content.get, page_index=-1) + @SubmissionController.register(Command('PROMPT')) + def prompt_subreddit(self): + "Open a prompt to navigate to a different subreddit" + + name = self.term.prompt_input('Enter page: /') + if name is not None: + self.subreddit_name = name + self.active = False + @SubmissionController.register(Command('SUBMISSION_OPEN_IN_BROWSER')) def open_link(self): "Open the selected item with the webbrowser" diff --git a/rtv/subreddit.py b/rtv/subreddit.py index 3c66314..c24a8f3 100644 --- a/rtv/subreddit.py +++ b/rtv/subreddit.py @@ -66,7 +66,7 @@ class SubredditPage(Page): if not self.term.loader.exception: self.nav = Navigator(self.content.get) - @SubredditController.register(Command('SUBREDDIT_PROMPT')) + @SubredditController.register(Command('PROMPT')) def prompt_subreddit(self): "Open a prompt to navigate to a different subreddit" @@ -111,6 +111,12 @@ class SubredditPage(Page): if data.get('url_type') == 'selfpost': self.config.history.add(data['url_full']) + if page.subreddit_name is not None: + self.refresh_content(order='ignore', + name=page.subreddit_name) + else: + self.refresh_content() + @SubredditController.register(Command('SUBREDDIT_OPEN_IN_BROWSER')) def open_link(self): "Open a link with the webbrowser" @@ -167,7 +173,11 @@ class SubredditPage(Page): page.loop() - self.refresh_content() + if page.subreddit_name is not None: + self.refresh_content(order='ignore', + name=page.subreddit_name) + else: + self.refresh_content() @SubredditController.register(Command('SUBREDDIT_OPEN_SUBSCRIPTIONS')) @logged_in @@ -184,9 +194,9 @@ class SubredditPage(Page): # When the user has chosen a subreddit in the subscriptions list, # refresh content with the selected subreddit - if page.subreddit_data is not None: + if page.subreddit_name is not None: self.refresh_content(order='ignore', - name=page.subreddit_data['name']) + name=page.subreddit_name) @SubredditController.register(Command('SUBREDDIT_OPEN_MULTIREDDITS')) @logged_in @@ -203,9 +213,9 @@ class SubredditPage(Page): # When the user has chosen a subreddit in the subscriptions list, # refresh content with the selected subreddit - if page.subreddit_data is not None: + if page.subreddit_name is not None: self.refresh_content(order='ignore', - name=page.subreddit_data['name']) + name=page.subreddit_name) def _draw_item(self, win, data, inverted): diff --git a/rtv/subscription.py b/rtv/subscription.py index e0e49b7..6142f87 100644 --- a/rtv/subscription.py +++ b/rtv/subscription.py @@ -22,7 +22,7 @@ class SubscriptionPage(Page): reddit, term.loader, content_type) self.nav = Navigator(self.content.get) self.content_type = content_type - self.subreddit_data = None + self.subreddit_name = None @SubscriptionController.register(Command('REFRESH')) def refresh_content(self, order=None, name=None): @@ -39,11 +39,20 @@ class SubscriptionPage(Page): if not self.term.loader.exception: self.nav = Navigator(self.content.get) + @SubscriptionController.register(Command('PROMPT')) + def prompt_subreddit(self): + "Open a prompt to navigate to a different subreddit" + + name = self.term.prompt_input('Enter page: /') + if name is not None: + self.subreddit_name = name + self.active = False + @SubscriptionController.register(Command('SUBSCRIPTION_SELECT')) def select_subreddit(self): "Store the selected subreddit and return to the subreddit page" - self.subreddit_data = self.content.get(self.nav.absolute_index) + self.subreddit_name = self.content.get(self.nav.absolute_index)['name'] self.active = False @SubscriptionController.register(Command('SUBSCRIPTION_EXIT')) diff --git a/rtv/templates/rtv.cfg b/rtv/templates/rtv.cfg index afb787f..c1e9de3 100644 --- a/rtv/templates/rtv.cfg +++ b/rtv/templates/rtv.cfg @@ -110,6 +110,7 @@ DELETE = d EDIT = e INBOX = i REFRESH = r, +PROMPT = / SAVE = w ; Submission page @@ -122,7 +123,6 @@ SUBMISSION_OPEN_IN_URLVIEWER = b ; Subreddit page SUBREDDIT_SEARCH = f -SUBREDDIT_PROMPT = / SUBREDDIT_POST = c SUBREDDIT_OPEN = l, SUBREDDIT_OPEN_IN_BROWSER = o, , , diff --git a/tests/test_subscription.py b/tests/test_subscription.py index 5d69f4c..a3a97b2 100644 --- a/tests/test_subscription.py +++ b/tests/test_subscription.py @@ -110,17 +110,17 @@ def test_subscription_select(subscription_page): # Select a subreddit subscription_page.controller.trigger(curses.KEY_ENTER) - assert subscription_page.subreddit_data is not None + assert subscription_page.subreddit_name is not None assert subscription_page.active is False def test_subscription_close(subscription_page): # Close the subscriptions page - subscription_page.subreddit_data = None + subscription_page.subreddit_name = None subscription_page.active = None subscription_page.controller.trigger('h') - assert subscription_page.subreddit_data is None + assert subscription_page.subreddit_name is None assert subscription_page.active is False