Got the prompt working from submissions / subscriptions.

This commit is contained in:
Michael Lazar
2016-08-05 17:56:36 -07:00
parent ddba5aab06
commit 6328407c32
7 changed files with 43 additions and 14 deletions

View File

@@ -14,6 +14,7 @@ Basic Commands
:``1-5``: Toggle post order (*hot*, *top*, *rising*, *new*, *controversial*) :``1-5``: Toggle post order (*hot*, *top*, *rising*, *new*, *controversial*)
:``r`` or ``F5``: Refresh page content :``r`` or ``F5``: Refresh page content
:``u``: Log in or switch accounts :``u``: Log in or switch accounts
:``/``: Open a prompt to switch subreddits
:``?``: Show the help screen :``?``: Show the help screen
:``q``/``Q``: Quit/Force quit :``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 :``l`` or ``►``: Enter the selected submission
:``o`` or ``ENTER``: Open the submission link with your web browser :``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 :``f``: Open a prompt to search the current subreddit
:``p``: Toggle between the front page and the last visited subreddit :``p``: Toggle between the front page and the last visited subreddit

View File

@@ -29,6 +29,7 @@ https://github.com/michael-lazar/rtv
1-5 : Toggle post order 1-5 : Toggle post order
r or F5 : Refresh page content r or F5 : Refresh page content
u : Log in or switch accounts u : Log in or switch accounts
/ : Open a prompt to switch subreddits
? : Show the help screen ? : Show the help screen
q/Q : Quit/Force quit q/Q : Quit/Force quit
@@ -45,7 +46,6 @@ https://github.com/michael-lazar/rtv
[Subreddit Commands] [Subreddit Commands]
l or ► : Enter the selected submission l or ► : Enter the selected submission
o or ENTER : Open the submission link with your web browser 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 f : Open a prompt to search the current subreddit
p : Return to the front page p : Return to the front page

View File

@@ -27,6 +27,7 @@ class SubmissionPage(Page):
self.content = SubmissionContent(submission, term.loader) self.content = SubmissionContent(submission, term.loader)
# Start at the submission post, which is indexed as -1 # Start at the submission post, which is indexed as -1
self.nav = Navigator(self.content.get, page_index=-1) self.nav = Navigator(self.content.get, page_index=-1)
self.subreddit_name = None
@SubmissionController.register(Command('SUBMISSION_TOGGLE_COMMENT')) @SubmissionController.register(Command('SUBMISSION_TOGGLE_COMMENT'))
def toggle_comment(self): def toggle_comment(self):
@@ -67,6 +68,15 @@ class SubmissionPage(Page):
if not self.term.loader.exception: if not self.term.loader.exception:
self.nav = Navigator(self.content.get, page_index=-1) 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')) @SubmissionController.register(Command('SUBMISSION_OPEN_IN_BROWSER'))
def open_link(self): def open_link(self):
"Open the selected item with the webbrowser" "Open the selected item with the webbrowser"

View File

@@ -66,7 +66,7 @@ class SubredditPage(Page):
if not self.term.loader.exception: if not self.term.loader.exception:
self.nav = Navigator(self.content.get) self.nav = Navigator(self.content.get)
@SubredditController.register(Command('SUBREDDIT_PROMPT')) @SubredditController.register(Command('PROMPT'))
def prompt_subreddit(self): def prompt_subreddit(self):
"Open a prompt to navigate to a different subreddit" "Open a prompt to navigate to a different subreddit"
@@ -111,6 +111,12 @@ class SubredditPage(Page):
if data.get('url_type') == 'selfpost': if data.get('url_type') == 'selfpost':
self.config.history.add(data['url_full']) 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')) @SubredditController.register(Command('SUBREDDIT_OPEN_IN_BROWSER'))
def open_link(self): def open_link(self):
"Open a link with the webbrowser" "Open a link with the webbrowser"
@@ -167,6 +173,10 @@ class SubredditPage(Page):
page.loop() page.loop()
if page.subreddit_name is not None:
self.refresh_content(order='ignore',
name=page.subreddit_name)
else:
self.refresh_content() self.refresh_content()
@SubredditController.register(Command('SUBREDDIT_OPEN_SUBSCRIPTIONS')) @SubredditController.register(Command('SUBREDDIT_OPEN_SUBSCRIPTIONS'))
@@ -184,9 +194,9 @@ class SubredditPage(Page):
# When the user has chosen a subreddit in the subscriptions list, # When the user has chosen a subreddit in the subscriptions list,
# refresh content with the selected subreddit # 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', self.refresh_content(order='ignore',
name=page.subreddit_data['name']) name=page.subreddit_name)
@SubredditController.register(Command('SUBREDDIT_OPEN_MULTIREDDITS')) @SubredditController.register(Command('SUBREDDIT_OPEN_MULTIREDDITS'))
@logged_in @logged_in
@@ -203,9 +213,9 @@ class SubredditPage(Page):
# When the user has chosen a subreddit in the subscriptions list, # When the user has chosen a subreddit in the subscriptions list,
# refresh content with the selected subreddit # 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', self.refresh_content(order='ignore',
name=page.subreddit_data['name']) name=page.subreddit_name)
def _draw_item(self, win, data, inverted): def _draw_item(self, win, data, inverted):

View File

@@ -22,7 +22,7 @@ class SubscriptionPage(Page):
reddit, term.loader, content_type) reddit, term.loader, content_type)
self.nav = Navigator(self.content.get) self.nav = Navigator(self.content.get)
self.content_type = content_type self.content_type = content_type
self.subreddit_data = None self.subreddit_name = None
@SubscriptionController.register(Command('REFRESH')) @SubscriptionController.register(Command('REFRESH'))
def refresh_content(self, order=None, name=None): def refresh_content(self, order=None, name=None):
@@ -39,11 +39,20 @@ class SubscriptionPage(Page):
if not self.term.loader.exception: if not self.term.loader.exception:
self.nav = Navigator(self.content.get) 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')) @SubscriptionController.register(Command('SUBSCRIPTION_SELECT'))
def select_subreddit(self): def select_subreddit(self):
"Store the selected subreddit and return to the subreddit page" "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 self.active = False
@SubscriptionController.register(Command('SUBSCRIPTION_EXIT')) @SubscriptionController.register(Command('SUBSCRIPTION_EXIT'))

View File

@@ -110,6 +110,7 @@ DELETE = d
EDIT = e EDIT = e
INBOX = i INBOX = i
REFRESH = r, <KEY_F5> REFRESH = r, <KEY_F5>
PROMPT = /
SAVE = w SAVE = w
; Submission page ; Submission page
@@ -122,7 +123,6 @@ SUBMISSION_OPEN_IN_URLVIEWER = b
; Subreddit page ; Subreddit page
SUBREDDIT_SEARCH = f SUBREDDIT_SEARCH = f
SUBREDDIT_PROMPT = /
SUBREDDIT_POST = c SUBREDDIT_POST = c
SUBREDDIT_OPEN = l, <KEY_RIGHT> SUBREDDIT_OPEN = l, <KEY_RIGHT>
SUBREDDIT_OPEN_IN_BROWSER = o, <LF>, <KEY_ENTER>, <KEY_ENTER> SUBREDDIT_OPEN_IN_BROWSER = o, <LF>, <KEY_ENTER>, <KEY_ENTER>

View File

@@ -110,17 +110,17 @@ def test_subscription_select(subscription_page):
# Select a subreddit # Select a subreddit
subscription_page.controller.trigger(curses.KEY_ENTER) 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 assert subscription_page.active is False
def test_subscription_close(subscription_page): def test_subscription_close(subscription_page):
# Close the subscriptions page # Close the subscriptions page
subscription_page.subreddit_data = None subscription_page.subreddit_name = None
subscription_page.active = None subscription_page.active = None
subscription_page.controller.trigger('h') 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 assert subscription_page.active is False