@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import time
|
||||
import curses
|
||||
|
||||
from . import docs
|
||||
from .content import SubmissionContent
|
||||
from .content import SubmissionContent, SubredditContent
|
||||
from .page import Page, PageController, logged_in
|
||||
from .objects import Navigator, Color, Command
|
||||
from .exceptions import TemporaryFileError
|
||||
@@ -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.selected_subreddit = None
|
||||
|
||||
@SubmissionController.register(Command('SUBMISSION_TOGGLE_COMMENT'))
|
||||
def toggle_comment(self):
|
||||
@@ -67,6 +68,19 @@ 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:
|
||||
with self.term.loader('Loading page'):
|
||||
content = SubredditContent.from_name(
|
||||
self.reddit, name, self.term.loader)
|
||||
if not self.term.loader.exception:
|
||||
self.selected_subreddit = content
|
||||
self.active = False
|
||||
|
||||
@SubmissionController.register(Command('SUBMISSION_OPEN_IN_BROWSER'))
|
||||
def open_link(self):
|
||||
"Open the selected item with the webbrowser"
|
||||
|
||||
@@ -30,7 +30,7 @@ class SubredditPage(Page):
|
||||
self.controller = SubredditController(self, keymap=config.keymap)
|
||||
self.content = SubredditContent.from_name(reddit, name, term.loader)
|
||||
self.nav = Navigator(self.content.get)
|
||||
self._toggled_subreddit = None
|
||||
self.toggled_subreddit = None
|
||||
|
||||
@SubredditController.register(Command('REFRESH'))
|
||||
def refresh_content(self, order=None, name=None):
|
||||
@@ -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"
|
||||
|
||||
@@ -83,9 +83,9 @@ class SubredditPage(Page):
|
||||
|
||||
if self.content.name != '/r/front':
|
||||
target = '/r/front'
|
||||
self._toggled_subreddit = self.content.name
|
||||
self.toggled_subreddit = self.content.name
|
||||
else:
|
||||
target = self._toggled_subreddit
|
||||
target = self.toggled_subreddit
|
||||
|
||||
# target still may be empty string if this command hasn't yet been used
|
||||
if target is not None:
|
||||
@@ -111,6 +111,12 @@ class SubredditPage(Page):
|
||||
if data.get('url_type') == 'selfpost':
|
||||
self.config.history.add(data['url_full'])
|
||||
|
||||
if page.selected_subreddit is not None:
|
||||
self.content = page.selected_subreddit
|
||||
self.nav = Navigator(self.content.get)
|
||||
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.selected_subreddit is not None:
|
||||
self.content = page.selected_subreddit
|
||||
self.nav = Navigator(self.content.get)
|
||||
else:
|
||||
self.refresh_content()
|
||||
|
||||
@SubredditController.register(Command('SUBREDDIT_OPEN_SUBSCRIPTIONS'))
|
||||
@logged_in
|
||||
@@ -184,9 +194,11 @@ 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:
|
||||
self.refresh_content(order='ignore',
|
||||
name=page.subreddit_data['name'])
|
||||
if page.selected_subreddit is not None:
|
||||
self.content = page.selected_subreddit
|
||||
self.nav = Navigator(self.content.get)
|
||||
else:
|
||||
self.refresh_content()
|
||||
|
||||
@SubredditController.register(Command('SUBREDDIT_OPEN_MULTIREDDITS'))
|
||||
@logged_in
|
||||
@@ -203,9 +215,11 @@ 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:
|
||||
self.refresh_content(order='ignore',
|
||||
name=page.subreddit_data['name'])
|
||||
if page.selected_subreddit is not None:
|
||||
self.content = page.selected_subreddit
|
||||
self.nav = Navigator(self.content.get)
|
||||
else:
|
||||
self.refresh_content()
|
||||
|
||||
def _draw_item(self, win, data, inverted):
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from __future__ import unicode_literals
|
||||
import curses
|
||||
|
||||
from .page import Page, PageController
|
||||
from .content import SubscriptionContent
|
||||
from .content import SubscriptionContent, SubredditContent
|
||||
from .objects import Color, Navigator, Command
|
||||
|
||||
|
||||
@@ -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.selected_subreddit = None
|
||||
|
||||
@SubscriptionController.register(Command('REFRESH'))
|
||||
def refresh_content(self, order=None, name=None):
|
||||
@@ -39,12 +39,30 @@ 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:
|
||||
with self.term.loader('Loading page'):
|
||||
content = SubredditContent.from_name(
|
||||
self.reddit, name, self.term.loader)
|
||||
if not self.term.loader.exception:
|
||||
self.selected_subreddit = content
|
||||
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.active = False
|
||||
name = self.content.get(self.nav.absolute_index)['name']
|
||||
with self.term.loader('Loading page'):
|
||||
content = SubredditContent.from_name(
|
||||
self.reddit, name, self.term.loader)
|
||||
if not self.term.loader.exception:
|
||||
self.selected_subreddit = content
|
||||
self.active = False
|
||||
|
||||
@SubscriptionController.register(Command('SUBSCRIPTION_EXIT'))
|
||||
def close_subscriptions(self):
|
||||
|
||||
@@ -110,6 +110,7 @@ DELETE = d
|
||||
EDIT = e
|
||||
INBOX = i
|
||||
REFRESH = r, <KEY_F5>
|
||||
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, <KEY_RIGHT>
|
||||
SUBREDDIT_OPEN_IN_BROWSER = o, <LF>, <KEY_ENTER>, <KEY_ENTER>
|
||||
|
||||
1175
tests/cassettes/test_submission_prompt.yaml
Normal file
1175
tests/cassettes/test_submission_prompt.yaml
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
6104
tests/cassettes/test_subscription_prompt.yaml
Normal file
6104
tests/cassettes/test_subscription_prompt.yaml
Normal file
File diff suppressed because it is too large
Load Diff
5374
tests/cassettes/test_subscription_select.yaml
Normal file
5374
tests/cassettes/test_subscription_select.yaml
Normal file
File diff suppressed because it is too large
Load Diff
@@ -95,6 +95,27 @@ def test_submission_open(submission_page, terminal):
|
||||
assert terminal.open_browser.called
|
||||
|
||||
|
||||
def test_submission_prompt(submission_page, terminal):
|
||||
|
||||
# Prompt for a different subreddit
|
||||
with mock.patch.object(terminal, 'prompt_input'):
|
||||
# Valid input
|
||||
submission_page.active = True
|
||||
submission_page.selected_subreddit = None
|
||||
terminal.prompt_input.return_value = 'front/top'
|
||||
submission_page.controller.trigger('/')
|
||||
assert not submission_page.active
|
||||
assert submission_page.selected_subreddit
|
||||
|
||||
# Invalid input
|
||||
submission_page.active = True
|
||||
submission_page.selected_subreddit = None
|
||||
terminal.prompt_input.return_value = 'front/pot'
|
||||
submission_page.controller.trigger('/')
|
||||
assert submission_page.active
|
||||
assert not submission_page.selected_subreddit
|
||||
|
||||
|
||||
def test_submission_move_top_bottom(submission_page):
|
||||
|
||||
submission_page.controller.trigger('G')
|
||||
|
||||
@@ -101,6 +101,7 @@ def test_subreddit_open(subreddit_page, terminal, config):
|
||||
config.history.add.assert_called_with(data['url_full'])
|
||||
|
||||
# Open the selected link externally
|
||||
data = subreddit_page.content.get(subreddit_page.nav.absolute_index)
|
||||
with mock.patch.object(terminal, 'open_link'), \
|
||||
mock.patch.object(config.history, 'add'):
|
||||
data['url_type'] = 'external'
|
||||
@@ -109,6 +110,7 @@ def test_subreddit_open(subreddit_page, terminal, config):
|
||||
config.history.add.assert_called_with(data['url_full'])
|
||||
|
||||
# Open the selected link within rtv
|
||||
data = subreddit_page.content.get(subreddit_page.nav.absolute_index)
|
||||
with mock.patch.object(subreddit_page, 'open_submission'), \
|
||||
mock.patch.object(config.history, 'add'):
|
||||
data['url_type'] = 'selfpost'
|
||||
|
||||
@@ -71,6 +71,27 @@ def test_subscription_refresh(subscription_page):
|
||||
assert not curses.flash.called
|
||||
|
||||
|
||||
def test_subscription_prompt(subscription_page, terminal):
|
||||
|
||||
# Prompt for a different subreddit
|
||||
with mock.patch.object(terminal, 'prompt_input'):
|
||||
# Valid input
|
||||
subscription_page.active = True
|
||||
subscription_page.selected_subreddit = None
|
||||
terminal.prompt_input.return_value = 'front/top'
|
||||
subscription_page.controller.trigger('/')
|
||||
assert not subscription_page.active
|
||||
assert subscription_page.selected_subreddit
|
||||
|
||||
# Invalid input
|
||||
subscription_page.active = True
|
||||
subscription_page.selected_subreddit = None
|
||||
terminal.prompt_input.return_value = 'front/pot'
|
||||
subscription_page.controller.trigger('/')
|
||||
assert subscription_page.active
|
||||
assert not subscription_page.selected_subreddit
|
||||
|
||||
|
||||
def test_subscription_move(subscription_page):
|
||||
|
||||
# Test movement
|
||||
@@ -110,17 +131,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.selected_subreddit 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.selected_subreddit = None
|
||||
subscription_page.active = None
|
||||
subscription_page.controller.trigger('h')
|
||||
assert subscription_page.subreddit_data is None
|
||||
assert subscription_page.selected_subreddit is None
|
||||
assert subscription_page.active is False
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user