Fixed browser links to selfposts. Added links to the submission page. #21

This commit is contained in:
Michael Lazar
2015-03-04 22:58:36 -08:00
parent 46be3d6833
commit 4e5f564db5
3 changed files with 19 additions and 14 deletions

View File

@@ -180,7 +180,8 @@ class BaseContent(object):
else '[deleted]') else '[deleted]')
data['permalink'] = clean(sub.permalink) data['permalink'] = clean(sub.permalink)
data['subreddit'] = strip_subreddit_url(sub.permalink) data['subreddit'] = strip_subreddit_url(sub.permalink)
data['url'] = ('(selfpost)' if is_selfpost(sub.url) else clean(sub.url)) data['url_full'] = clean(sub.url)
data['url'] = ('selfpost' if is_selfpost(sub.url) else clean(sub.url))
return data return data

View File

@@ -1,5 +1,6 @@
import curses import curses
import sys import sys
import webbrowser
import six import six
@@ -36,24 +37,23 @@ class SubmissionPage(BasePage):
self.move_cursor_down() self.move_cursor_down()
self.clear_input_queue() self.clear_input_queue()
# Refresh page
elif cmd in (curses.KEY_F5, ord('r')): elif cmd in (curses.KEY_F5, ord('r')):
self.refresh_content() self.refresh_content()
self.draw() self.draw()
# Show / hide a comment tree
elif cmd in (curses.KEY_RIGHT, curses.KEY_ENTER, ord('l')): elif cmd in (curses.KEY_RIGHT, curses.KEY_ENTER, ord('l')):
self.toggle_comment() self.toggle_comment()
self.draw() self.draw()
elif cmd == ord('o'):
self.open_link()
elif cmd == curses.KEY_RESIZE: elif cmd == curses.KEY_RESIZE:
self.draw() self.draw()
# Go back
elif cmd in (ESCAPE, curses.KEY_LEFT, ord('h')): elif cmd in (ESCAPE, curses.KEY_LEFT, ord('h')):
break break
# Quit
elif cmd == ord('q'): elif cmd == ord('q'):
sys.exit() sys.exit()
@@ -70,6 +70,13 @@ class SubmissionPage(BasePage):
self.nav.page_index, self.nav.cursor_index = -1, 0 self.nav.page_index, self.nav.cursor_index = -1, 0
self.nav.inverted = False self.nav.inverted = False
def open_link(self):
# Always open the page for the submission
# May want to expand at some point to open comment permalinks
url = self.content.get(-1)['permalink']
webbrowser.open_new_tab(url)
def draw_item(self, win, data, inverted=False): def draw_item(self, win, data, inverted=False):
if data['type'] == 'MoreComments': if data['type'] == 'MoreComments':

View File

@@ -34,7 +34,6 @@ class SubredditPage(BasePage):
self.move_cursor_down() self.move_cursor_down()
self.clear_input_queue() self.clear_input_queue()
# View submission
elif cmd in (curses.KEY_RIGHT, curses.KEY_ENTER, ord('l')): elif cmd in (curses.KEY_RIGHT, curses.KEY_ENTER, ord('l')):
self.open_submission() self.open_submission()
self.draw() self.draw()
@@ -42,12 +41,10 @@ class SubredditPage(BasePage):
elif cmd == ord('o'): elif cmd == ord('o'):
self.open_link() self.open_link()
# Enter edit mode to change subreddit
elif cmd == ord('/'): elif cmd == ord('/'):
self.prompt_subreddit() self.prompt_subreddit()
self.draw() self.draw()
# Refresh page
elif cmd in (curses.KEY_F5, ord('r')): elif cmd in (curses.KEY_F5, ord('r')):
self.refresh_content() self.refresh_content()
self.draw() self.draw()
@@ -55,7 +52,6 @@ class SubredditPage(BasePage):
elif cmd == curses.KEY_RESIZE: elif cmd == curses.KEY_RESIZE:
self.draw() self.draw()
# Quit
elif cmd == ord('q'): elif cmd == ord('q'):
sys.exit() sys.exit()
@@ -99,6 +95,11 @@ class SubredditPage(BasePage):
page = SubmissionPage(self.stdscr, self.reddit, submission=submission) page = SubmissionPage(self.stdscr, self.reddit, submission=submission)
page.loop() page.loop()
def open_link(self):
url = self.content.get(self.nav.absolute_index)['url_full']
webbrowser.open_new_tab(url)
@staticmethod @staticmethod
def draw_item(win, data, inverted=False): def draw_item(win, data, inverted=False):
@@ -131,8 +132,4 @@ class SubredditPage(BasePage):
text = '{author}'.format(**data) text = '{author}'.format(**data)
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)