Merge pull request #20 from mekhami/master

Added functionality to open the submission link in the browser.
This commit is contained in:
michael-lazar
2015-03-04 13:20:17 -08:00
2 changed files with 9 additions and 0 deletions

View File

@@ -54,6 +54,7 @@ In subreddit mode you can browse through the top submissions on either the front
:``Right`` or ``Enter``: Open the currently selected submission in a new page. :``Right`` or ``Enter``: Open the currently selected submission in a new page.
:``/``: Open a prompt to switch to a different subreddit. For example, pressing ``/`` and typing *python* will open */r/python*. You can return to Reddit's front page by using the alias */r/front*. :``/``: Open a prompt to switch to a different subreddit. For example, pressing ``/`` and typing *python* will open */r/python*. You can return to Reddit's front page by using the alias */r/front*.
:``o``: Opens the url for a link-post in the default browser.
**Submission Mode** **Submission Mode**

View File

@@ -1,5 +1,6 @@
import curses import curses
import sys import sys
import webbrowser
from requests.exceptions import HTTPError from requests.exceptions import HTTPError
from .errors import SubredditNameError from .errors import SubredditNameError
@@ -38,6 +39,9 @@ class SubredditPage(BasePage):
self.open_submission() self.open_submission()
self.draw() self.draw()
elif cmd == ord('o'):
self.open_link()
# Enter edit mode to change subreddit # Enter edit mode to change subreddit
elif cmd == ord('/'): elif cmd == ord('/'):
self.prompt_subreddit() self.prompt_subreddit()
@@ -128,3 +132,7 @@ class SubredditPage(BasePage):
win.addnstr(row, 1, text, n_cols-1, curses.A_BOLD) win.addnstr(row, 1, text, n_cols-1, curses.A_BOLD)
text = ' {subreddit}'.format(**data) text = ' {subreddit}'.format(**data)
win.addnstr(text, n_cols - win.getyx()[1], Color.YELLOW) win.addnstr(text, n_cols - win.getyx()[1], Color.YELLOW)
def open_link(self):
url = self.content.get(self.nav.absolute_index)['url']
webbrowser.open_new_tab(url)