Refactoring and adding some new themes

This commit is contained in:
Michael Lazar
2017-09-20 01:04:23 -04:00
parent d8213f2271
commit 68906b2a67
11 changed files with 356 additions and 213 deletions

View File

@@ -11,7 +11,7 @@ import six
from kitchen.text.display import textual_width
from . import docs
from .theme import ThemeList
from .theme import get_next_theme, get_previous_theme
from .objects import Controller, Command
from .clipboard import copy
from .exceptions import TemporaryFileError, ProgramError
@@ -52,9 +52,6 @@ class Page(object):
self.controller = None
self.copy_to_clipboard = copy
# TODO: does this need to be a global?
self.theme_list = ThemeList(term.theme)
self.active = True
self._row = 0
self._subwindows = None
@@ -101,7 +98,7 @@ class Page(object):
@PageController.register(Command('PREVIOUS_THEME'))
def previous_theme(self):
theme = self.theme_list.previous()
theme = get_previous_theme(self.term.theme)
self.term.set_theme(theme)
self.draw()
message = self.term.theme.display_string
@@ -109,7 +106,7 @@ class Page(object):
@PageController.register(Command('NEXT_THEME'))
def next_theme(self):
theme = self.theme_list.next()
theme = get_next_theme(self.term.theme)
self.term.set_theme(theme)
self.draw()
message = self.term.theme.display_string
@@ -367,7 +364,7 @@ class Page(object):
window = self.term.stdscr.derwin(1, n_cols, self._row, 0)
window.erase()
# curses.bkgd expects bytes in py2 and unicode in py3
window.bkgd(str(' '), self.term.attr('PageTitle'))
window.bkgd(str(' '), self.term.attr('TitleBar'))
sub_name = self.content.name
sub_name = sub_name.replace('/r/front', 'Front Page')
@@ -420,7 +417,7 @@ class Page(object):
n_rows, n_cols = self.term.stdscr.getmaxyx()
window = self.term.stdscr.derwin(1, n_cols, self._row, 0)
window.erase()
window.bkgd(str(' '), self.term.attr('PageOrder'))
window.bkgd(str(' '), self.term.attr('OrderBar'))
banner = docs.BANNER_SEARCH if self.content.query else docs.BANNER
items = banner.strip().split(' ')
@@ -432,7 +429,7 @@ class Page(object):
if self.content.order is not None:
order = self.content.order.split('-')[0]
col = text.find(order) - 3
attr = self.term.attr('PageOrderHighlight')
attr = self.term.attr('OrderBarHighlight')
window.chgat(0, col, 3, attr)
self._row += 1
@@ -499,12 +496,10 @@ class Page(object):
# pushed out of bounds
self.nav.cursor_index = len(self._subwindows) - 1
# TODO: Don't highlight the submission box
# Now that the windows are setup, we can take a second pass through
# to draw the content
# to draw the text onto each subwindow
for index, (win, data, inverted) in enumerate(self._subwindows):
if index == self.nav.cursor_index:
if self.nav.absolute_index >= 0 and index == self.nav.cursor_index:
win.bkgd(str(' '), self.term.attr('Selected'))
with self.term.theme.turn_on_selected():
self._draw_item(win, data, inverted)
@@ -519,7 +514,7 @@ class Page(object):
n_rows, n_cols = self.term.stdscr.getmaxyx()
window = self.term.stdscr.derwin(1, n_cols, self._row, 0)
window.erase()
window.bkgd(str(' '), self.term.attr('Help'))
window.bkgd(str(' '), self.term.attr('HelpBar'))
text = self.FOOTER.strip()
self.term.add_line(window, text, 0, 0)