Merge branch 'master' into woorst-imgur_api

This commit is contained in:
Michael Lazar
2017-07-25 00:54:19 -04:00
10 changed files with 3601 additions and 941 deletions

View File

@@ -326,6 +326,7 @@ class SubmissionContent(Content):
self.max_indent_level = max_indent_level
self.name = submission_data['permalink']
self.order = order
self.query = None
self._loader = loader
self._submission = submission
self._submission_data = submission_data
@@ -435,10 +436,12 @@ class SubredditContent(Content):
list for repeat access.
"""
def __init__(self, name, submissions, loader, order=None, max_title_rows=4):
def __init__(self, name, submissions, loader, order=None,
max_title_rows=4, query=None):
self.name = name
self.order = order
self.query = query
self.max_title_rows = max_title_rows
self._loader = loader
self._submissions = submissions
@@ -603,7 +606,8 @@ class SubredditContent(Content):
display_name = '/r/{0}'.format(subreddit.display_name)
# We made it!
return cls(display_name, submissions, loader, order=display_order)
return cls(display_name, submissions, loader, order=display_order,
query=query)
@property
def range(self):
@@ -659,6 +663,7 @@ class SubscriptionContent(Content):
self.name = name
self.order = None
self.query = None
self._loader = loader
self._subscriptions = subscriptions
self._subscription_data = []

View File

@@ -643,14 +643,16 @@ class KeyMap(object):
self.set_bindings(bindings)
def set_bindings(self, bindings):
# Clear the keymap before applying the bindings to avoid confusion.
# If a user defines custom bindings in their config file, they must
# explicitly define ALL of the bindings.
self._keymap = {}
new_keymap = {}
for command, keys in bindings.items():
if not isinstance(command, Command):
command = Command(command)
self._keymap[command] = keys
new_keymap[command] = keys
if not self._keymap:
self._keymap = new_keymap
else:
self._keymap.update(new_keymap)
def get(self, command):
if not isinstance(command, Command):
@@ -694,4 +696,4 @@ class KeyMap(object):
except (AttributeError, ValueError, TypeError):
raise exceptions.ConfigError('Invalid configuration! "%s" is not a '
'valid key' % key)
'valid key' % key)

View File

@@ -408,6 +408,10 @@ class Page(object):
sub_name = sub_name.replace('/r/front', 'Front Page')
sub_name = sub_name.replace('/u/me', 'My Submissions')
sub_name = sub_name.replace('/u/saved', 'My Saved Submissions')
query = self.content.query
if query:
sub_name = 'Searching {0}: {1}'.format(sub_name, query)
self.term.add_line(window, sub_name, 0, 0)
# Set the terminal title

View File

@@ -40,6 +40,13 @@ class SubredditPage(Page):
"Re-download all submissions and reset the page index"
order = order or self.content.order
# Preserve the query if staying on the current page
if name is None:
query = self.content.query
else:
query = None
name = name or self.content.name
# Hack to allow an order specified in the name by prompt_subreddit() to
@@ -49,7 +56,7 @@ class SubredditPage(Page):
with self.term.loader('Refreshing page'):
self.content = SubredditContent.from_name(
self.reddit, name, self.term.loader, order=order)
self.reddit, name, self.term.loader, order=order, query=query)
if not self.term.loader.exception:
self.nav = Navigator(self.content.get)
@@ -290,4 +297,4 @@ class SubredditPage(Page):
self.term.add_line(win, text, attr=Color.YELLOW)
if data['flair']:
text = ' {flair}'.format(**data)
self.term.add_line(win, text, attr=Color.RED)
self.term.add_line(win, text, attr=Color.RED)

View File

@@ -59,7 +59,7 @@ class Terminal(object):
self.loader = LoadScreen(self)
self._display = None
self._mailcap_dict = mailcap.getcaps()
self._term = os.environ['TERM']
self._term = os.environ.get('TERM')
# This is a hack, the MIME parsers should be stateless
# but we need to load the imgur credentials from the config