diff --git a/README.rst b/README.rst index c3e9e92..4be1e42 100644 --- a/README.rst +++ b/README.rst @@ -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. :``/``: 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** diff --git a/rtv/subreddit.py b/rtv/subreddit.py index d2501c0..d477d7d 100644 --- a/rtv/subreddit.py +++ b/rtv/subreddit.py @@ -1,5 +1,6 @@ import curses import sys +import webbrowser from requests.exceptions import HTTPError from .errors import SubredditNameError @@ -38,6 +39,9 @@ class SubredditPage(BasePage): self.open_submission() self.draw() + elif cmd == ord('o'): + self.open_link() + # Enter edit mode to change subreddit elif cmd == ord('/'): self.prompt_subreddit() @@ -128,3 +132,7 @@ class SubredditPage(BasePage): win.addnstr(row, 1, text, n_cols-1, curses.A_BOLD) text = ' {subreddit}'.format(**data) 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)