Merge branch 'master' into themes

This commit is contained in:
Michael Lazar
2017-09-07 22:31:43 -04:00
65 changed files with 20824 additions and 2168 deletions

View File

@@ -116,32 +116,29 @@ class Page(object):
@PageController.register(Command('SORT_HOT'))
def sort_content_hot(self):
self.refresh_content(order='hot')
if self.content.query:
self.refresh_content(order='relevance')
else:
self.refresh_content(order='hot')
@PageController.register(Command('SORT_TOP'))
def sort_content_top(self):
choices = {
'\n': 'top',
'1': 'top-hour',
'2': 'top-day',
'3': 'top-week',
'4': 'top-month',
'5': 'top-year',
'6': 'top-all'}
message = docs.TIME_ORDER_MENU.strip().splitlines()
ch = self.term.show_notification(message)
ch = six.unichr(ch)
if ch not in choices:
order = self._prompt_period('top')
if order is None:
self.term.show_notification('Invalid option')
return
self.refresh_content(order=choices[ch])
else:
self.refresh_content(order=order)
@PageController.register(Command('SORT_RISING'))
def sort_content_rising(self):
self.refresh_content(order='rising')
if self.content.query:
order = self._prompt_period('comments')
if order is None:
self.term.show_notification('Invalid option')
else:
self.refresh_content(order=order)
else:
self.refresh_content(order='rising')
@PageController.register(Command('SORT_NEW'))
def sort_content_new(self):
@@ -149,24 +146,14 @@ class Page(object):
@PageController.register(Command('SORT_CONTROVERSIAL'))
def sort_content_controversial(self):
choices = {
'\n': 'controversial',
'1': 'controversial-hour',
'2': 'controversial-day',
'3': 'controversial-week',
'4': 'controversial-month',
'5': 'controversial-year',
'6': 'controversial-all'}
message = docs.TIME_ORDER_MENU.strip().splitlines()
ch = self.term.show_notification(message)
ch = six.unichr(ch)
if ch not in choices:
self.term.show_notification('Invalid option')
return
self.refresh_content(order=choices[ch])
if self.content.query:
self.term.flash()
else:
order = self._prompt_period('controversial')
if order is None:
self.term.show_notification('Invalid option')
else:
self.refresh_content(order=order)
@PageController.register(Command('MOVE_UP'))
def move_cursor_up(self):
@@ -421,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
@@ -466,7 +457,9 @@ class Page(object):
window.erase()
window.bkgd(str(' '), self.term.attr('order_bar'))
items = docs.BANNER.strip().split(' ')
banner = docs.BANNER_SEARCH if self.content.query else docs.BANNER
items = banner.strip().split(' ')
distance = (n_cols - sum(len(t) for t in items) - 1) / (len(items) - 1)
spacing = max(1, int(distance)) * ' '
text = spacing.join(items)
@@ -574,3 +567,20 @@ class Page(object):
valid, redraw = self.nav.move_page(direction, len(self._subwindows)-1)
if not valid:
self.term.flash()
def _prompt_period(self, order):
choices = {
'\n': order,
'1': '{0}-hour'.format(order),
'2': '{0}-day'.format(order),
'3': '{0}-week'.format(order),
'4': '{0}-month'.format(order),
'5': '{0}-year'.format(order),
'6': '{0}-all'.format(order)}
message = docs.TIME_ORDER_MENU.strip().splitlines()
ch = self.term.show_notification(message)
ch = six.unichr(ch)
return choices.get(ch)