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

@@ -217,6 +217,7 @@ class Content(object):
data['title'] = sub.title data['title'] = sub.title
data['text'] = sub.selftext data['text'] = sub.selftext
data['created'] = cls.humanize_timestamp(sub.created_utc) data['created'] = cls.humanize_timestamp(sub.created_utc)
data['created_long'] = cls.humanize_timestamp(sub.created_utc, True)
data['comments'] = '{0} comments'.format(sub.num_comments) data['comments'] = '{0} comments'.format(sub.num_comments)
data['score'] = '{0} pts'.format('-' if sub.hide_score else sub.score) data['score'] = '{0} pts'.format('-' if sub.hide_score else sub.score)
data['author'] = name data['author'] = name

View File

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

View File

@@ -400,14 +400,14 @@ class SubmissionPage(Page):
self.term.add_space(win) self.term.add_space(win)
self.term.add_line(win, '{flair}'.format(**data), attr=attr) self.term.add_line(win, '{flair}'.format(**data), attr=attr)
attr = self.term.attr('Created')
self.term.add_space(win)
self.term.add_line(win, '{created}'.format(**data), attr=attr)
attr = self.term.attr('SubmissionSubreddit') attr = self.term.attr('SubmissionSubreddit')
self.term.add_space(win) self.term.add_space(win)
self.term.add_line(win, '/r/{subreddit}'.format(**data), attr=attr) self.term.add_line(win, '/r/{subreddit}'.format(**data), attr=attr)
attr = self.term.attr('Created')
self.term.add_space(win)
self.term.add_line(win, '{created_long}'.format(**data), attr=attr)
row = len(data['split_title']) + 2 row = len(data['split_title']) + 2
if data['url_full'] in self.config.history: if data['url_full'] in self.config.history:
attr = self.term.attr('LinkSeen') attr = self.term.attr('LinkSeen')

View File

@@ -50,31 +50,37 @@ class Theme(object):
for i in range(256): for i in range(256):
COLOR_CODES['ansi_{0}'.format(i)] = i COLOR_CODES['ansi_{0}'.format(i)] = i
# TODO: Do another pass through these names # TODO: Apply selected on top of items, not underneath them
# For compatibility with as many terminals as possible, the default theme # For compatibility with as many terminals as possible, the default theme
# can only use the 8 basic colors with the default color as the background # can only use the 8 basic colors with the default color as the background
DEFAULT_THEME = { DEFAULT_THEME = {
'modifiers': {
'Normal': (None, None, None), 'Normal': (None, None, None),
'Selected': (None, None, None), 'Selected': (None, None, None),
'SelectedCursor': (None, None, curses.A_REVERSE), 'SelectedCursor': (None, None, curses.A_REVERSE),
},
'PageTitle': (curses.COLOR_CYAN, None, curses.A_BOLD | curses.A_REVERSE), 'page': {
'PageOrder': (curses.COLOR_YELLOW, None, curses.A_BOLD), 'TitleBar': (curses.COLOR_CYAN, None, curses.A_BOLD | curses.A_REVERSE),
'PageOrderHighlight': (curses.COLOR_YELLOW, None, curses.A_BOLD | curses.A_REVERSE), 'OrderBar': (curses.COLOR_YELLOW, None, curses.A_BOLD),
'Help': (curses.COLOR_CYAN, None, curses.A_BOLD | curses.A_REVERSE), 'OrderBarHighlight': (curses.COLOR_YELLOW, None, curses.A_BOLD | curses.A_REVERSE),
'HelpBar': (curses.COLOR_CYAN, None, curses.A_BOLD | curses.A_REVERSE),
'Prompt': (curses.COLOR_CYAN, None, curses.A_BOLD | curses.A_REVERSE), 'Prompt': (curses.COLOR_CYAN, None, curses.A_BOLD | curses.A_REVERSE),
'NoticeInfo': (None, None, curses.A_BOLD), 'NoticeInfo': (None, None, curses.A_BOLD),
'NoticeLoading': (None, None, curses.A_BOLD), 'NoticeLoading': (None, None, curses.A_BOLD),
'NoticeError': (None, None, curses.A_BOLD), 'NoticeError': (None, None, curses.A_BOLD),
'NoticeSuccess': (None, None, curses.A_BOLD), 'NoticeSuccess': (None, None, curses.A_BOLD),
},
# Fields that might be highlighted by the "SelectedCursor" element
'cursor': {
'CursorBlock': (None, None, None), 'CursorBlock': (None, None, None),
'CursorBar1': (curses.COLOR_MAGENTA, None, None), 'CursorBar1': (curses.COLOR_MAGENTA, None, None),
'CursorBar2': (curses.COLOR_CYAN, None, None), 'CursorBar2': (curses.COLOR_CYAN, None, None),
'CursorBar3': (curses.COLOR_GREEN, None, None), 'CursorBar3': (curses.COLOR_GREEN, None, None),
'CursorBar4': (curses.COLOR_YELLOW, None, None), 'CursorBar4': (curses.COLOR_YELLOW, None, None),
},
# Fields that might be highlighted by the "Selected" element
'normal': {
'CommentAuthor': (curses.COLOR_BLUE, None, curses.A_BOLD), 'CommentAuthor': (curses.COLOR_BLUE, None, curses.A_BOLD),
'CommentAuthorSelf': (curses.COLOR_GREEN, None, curses.A_BOLD), 'CommentAuthorSelf': (curses.COLOR_GREEN, None, curses.A_BOLD),
'CommentCount': (None, None, None), 'CommentCount': (None, None, None),
@@ -104,60 +110,10 @@ class Theme(object):
'LinkSeen': (curses.COLOR_MAGENTA, None, curses.A_UNDERLINE), 'LinkSeen': (curses.COLOR_MAGENTA, None, curses.A_UNDERLINE),
'UserFlair': (curses.COLOR_YELLOW, None, curses.A_BOLD) 'UserFlair': (curses.COLOR_YELLOW, None, curses.A_BOLD)
} }
}
# List of elements that might be highlighted by the "Selected" row DEFAULT_ELEMENTS = {k: v for group in DEFAULT_THEME.values()
SELECTED_ELEMENTS = [ for k, v in group.items()}
'CommentAuthor',
'CommentAuthorSelf',
'CommentCount',
'CommentText',
'Created',
'Downvote',
'Gold',
'HiddenCommentExpand',
'HiddenCommentText',
'MultiredditName',
'MultiredditText',
'NeutralVote',
'NSFW',
'Saved',
'Score',
'Separator',
'Stickied',
'SubscriptionName',
'SubscriptionText',
'SubmissionAuthor',
'SubmissionFlair',
'SubmissionSubreddit',
'SubmissionText',
'SubmissionTitle',
'Upvote',
'Link',
'LinkSeen',
'UserFlair'
]
# List of elements that might be highlighted by the "SelectedCursor" row
SELECTED_CURSOR_ELEMENTS = [
'CursorBlock',
'CursorBar1',
'CursorBar2',
'CursorBar3',
'CursorBar4'
]
# List of page elements that cannot be selected
PAGE_ELEMENTS = [
'PageOrder',
'PageOrderHighlight',
'PageTitle',
'Help',
'Prompt',
'NoticeInfo',
'NoticeLoading',
'NoticeError',
'NoticeSuccess',
]
# The SubmissionPage uses this to determine which color bar to use # The SubmissionPage uses this to determine which color bar to use
CURSOR_BARS = ['CursorBar1', 'CursorBar2', 'CursorBar3', 'CursorBar4'] CURSOR_BARS = ['CursorBar1', 'CursorBar2', 'CursorBar3', 'CursorBar4']
@@ -194,11 +150,11 @@ class Theme(object):
self.required_colors = 0 self.required_colors = 0
if elements is None: if elements is None:
elements = self.DEFAULT_THEME.copy() elements = self.DEFAULT_ELEMENTS.copy()
# Set any elements that weren't defined by the config to fallback to # Set any elements that weren't defined by the config to fallback to
# the default color and attributes # the default color and attributes
for key in self.DEFAULT_THEME.keys(): for key in self.DEFAULT_ELEMENTS.keys():
if key not in elements: if key not in elements:
elements[key] = (None, None, None) elements[key] = (None, None, None)
@@ -210,17 +166,17 @@ class Theme(object):
# 1. The default state - inherits from "Normal" # 1. The default state - inherits from "Normal"
# 2. The selected state - inherits from "Selected" and is # 2. The selected state - inherits from "Selected" and is
# prefixed by the "@" sign. # prefixed by the "@" sign.
for name in self.SELECTED_ELEMENTS: for name in self.DEFAULT_THEME['normal']:
dest = '@{0}'.format(name) dest = '@{0}'.format(name)
self._set_fallback(elements, name, 'Selected', dest) self._set_fallback(elements, name, 'Selected', dest)
self._set_fallback(elements, name, 'Normal') self._set_fallback(elements, name, 'Normal')
for name in self.SELECTED_CURSOR_ELEMENTS: for name in self.DEFAULT_THEME['cursor']:
dest = '@{0}'.format(name) dest = '@{0}'.format(name)
self._set_fallback(elements, name, 'SelectedCursor', dest) self._set_fallback(elements, name, 'SelectedCursor', dest)
self._set_fallback(elements, name, 'Normal') self._set_fallback(elements, name, 'Normal')
for name in self.PAGE_ELEMENTS: for name in self.DEFAULT_THEME['page']:
self._set_fallback(elements, name, 'Normal') self._set_fallback(elements, name, 'Normal')
self.elements = elements self.elements = elements
@@ -233,14 +189,15 @@ class Theme(object):
colors.add(bg) colors.add(bg)
color_pairs.add((fg, bg)) color_pairs.add((fg, bg))
# Don't count the default (-1, -1) as a color pair because it doesn't # Don't count the default (-1, -1) as a color pair because it
# need to be initialized by curses.init_pair(). # doesn't need to be initialized by curses.init_pair().
color_pairs.discard((-1, -1)) color_pairs.discard((-1, -1))
self.required_color_pairs = len(color_pairs) self.required_color_pairs = len(color_pairs)
# Determine how many colors the terminal needs to support in order to # Determine how many colors the terminal needs to support in order
# be able to use the theme. This uses the common breakpoints that 99% # to be able to use the theme. This uses the common breakpoints
# of terminals follow and doesn't take into account 88 color themes. # that 99% of terminals follow and doesn't take into account
# 88 color themes.
self.required_colors = None self.required_colors = None
for marker in [0, 8, 16, 256]: for marker in [0, 8, 16, 256]:
if max(colors) < marker: if max(colors) < marker:
@@ -353,7 +310,7 @@ class Theme(object):
@classmethod @classmethod
def print_themes(cls, path=THEMES): def print_themes(cls, path=THEMES):
""" """
Prints a human-readable summary of all of the installed themes to stdout. Prints a human-readable summary of the installed themes to stdout.
This is intended to be used as a command-line utility, outside of the This is intended to be used as a command-line utility, outside of the
main curses display loop. main curses display loop.
@@ -436,7 +393,7 @@ class Theme(object):
elements = {} elements = {}
for element, line in config.items('theme'): for element, line in config.items('theme'):
if element not in cls.DEFAULT_THEME: if element not in cls.DEFAULT_ELEMENTS:
# Could happen if using a new config with an older version # Could happen if using a new config with an older version
# of the software # of the software
_logger.info('Skipping element %s', element) _logger.info('Skipping element %s', element)
@@ -550,52 +507,47 @@ class ThemeList(object):
to cycle through all of the available themes. to cycle through all of the available themes.
""" """
def __init__(self, current_theme=None): def __init__(self):
self.index = 0
self.current_theme = current_theme
self.themes = None self.themes = None
self.errors = None self.errors = None
def load(self): def reload(self):
""" """
This acts as a lazy load, it won't read all of the theme files from This acts as a lazy load, it won't read all of the theme files from
disk until the first time somebody tries to access the theme list. disk until the first time somebody tries to access the theme list.
""" """
self.themes, self.errors = Theme.list_themes() self.themes, self.errors = Theme.list_themes()
if self.current_theme is not None: def _step(self, theme, direction):
"""
Traverse the list in the given direction and return the next theme
"""
if not self.themes:
self.reload()
# Try to find the starting index # Try to find the starting index
key = (self.current_theme.source, self.current_theme.name) key = (theme.source, theme.name)
for i, theme in enumerate(self.themes): for i, theme in enumerate(self.themes):
if (theme.source, theme.name) == key: if (theme.source, theme.name) == key:
self.index = i index = i
break break
else: else:
# If the current_theme was set from a custom source it might # If the theme was set from a custom source it might
# not be a part of the list returned by list_themes(). # not be a part of the list returned by list_themes().
self.themes.insert(0, self.current_theme) self.themes.insert(0, theme)
index = 0
self.current_theme = self.themes[self.index] index = (index + direction) % len(self.themes)
new_theme = self.themes[index]
return new_theme
def next(self): def next(self, theme):
""" return self._step(theme, 1)
Retrieve the next theme in the list
"""
if not self.themes:
self.load()
self.index = (self.index + 1) % len(self.themes) def previous(self, theme):
self.current_theme = self.themes[self.index] return self._step(theme, -1)
return self.current_theme
def previous(self):
"""
Retrieve the previous theme in the list
"""
if not self.themes:
self.load()
self.index = (self.index - 1) % len(self.themes) theme_list = ThemeList()
self.current_theme = self.themes[self.index] get_next_theme = theme_list.next
return self.current_theme get_previous_theme = theme_list.previous

View File

@@ -1,16 +1,13 @@
# http://www.calmar.ws/vim/256-xterm-24bit-rgb-color-chart.html
# https://upload.wikimedia.org/wikipedia/commons/1/15/Xterm_256color_chart.svg
[theme] [theme]
;<element> = <foreground> <background> <attributes> ;<element> = <foreground> <background> <attributes>
Normal = default default - Normal = default default -
Selected = - - - Selected = - - -
SelectedCursor = - - reverse SelectedCursor = - - reverse
PageTitle = cyan - bold+reverse TitleBar = cyan - bold+reverse
PageOrder = yellow - bold OrderBar = yellow - bold
PageOrderHighlight = yellow - bold+reverse OrderBarHighlight = yellow - bold+reverse
Help = cyan - bold+reverse HelpBar = cyan - bold+reverse
Prompt = cyan - bold+reverse Prompt = cyan - bold+reverse
NoticeInfo = - - bold NoticeInfo = - - bold
NoticeLoading = - - bold NoticeLoading = - - bold

View File

@@ -0,0 +1,50 @@
[theme]
;<element> = <foreground> <background> <attributes>
Normal = default default -
Selected = - - -
SelectedCursor = - - reverse
TitleBar = cyan - bold+reverse
OrderBar = yellow - bold
OrderBarHighlight = yellow - bold+reverse
HelpBar = cyan - bold+reverse
Prompt = cyan - bold+reverse
NoticeInfo = - - bold
NoticeLoading = - - bold
NoticeError = - - bold
NoticeSuccess = - - bold
CursorBlock = - - -
CursorBar1 = magenta - -
CursorBar2 = cyan - -
CursorBar3 = green - -
CursorBar4 = yellow - -
CommentAuthor = cyan - bold
CommentAuthorSelf = green - bold
CommentCount = - - -
CommentText = - - -
Created = - - -
Downvote = red - bold
Gold = yellow - bold
HiddenCommentExpand = - - bold
HiddenCommentText = - - -
MultiredditName = yellow - bold
MultiredditText = - - -
NeutralVote = - - bold
NSFW = red - bold+reverse
Saved = green - -
Score = - - -
Separator = - - bold
Stickied = green - -
SubscriptionName = yellow - bold
SubscriptionText = - - -
SubmissionAuthor = green - bold
SubmissionFlair = red - -
SubmissionSubreddit = yellow - -
SubmissionText = - - -
SubmissionTitle = - - bold
Upvote = green - bold
Link = cyan - underline
LinkSeen = magenta - underline
UserFlair = yellow - bold

73
rtv/themes/molokai.cfg Normal file
View File

@@ -0,0 +1,73 @@
# https://github.com/tomasr/molokai
# normal ansi_252, ansi_234
# line number ansi_239, ansi_235
# cursor ansi_252, ansi_236
# pmenusel ansi_255, ansi_242
# text - normal ansi_252
# text - dim ansi_244
# text - ultra dim ansi_241
# purple ansi_141
# green ansi_154
# magenta ansi_199, ansi_16
# gold ansi_222, ansi_233
# red ansi_197
# red - dim ansi_203
# orange ansi_208
# blue ansi_81
# blue - dim ansi_67, ansi_16
[theme]
;<element> = <foreground> <background> <attributes>
Normal = ansi_252 ansi_234 -
Selected = - ansi_236 -
SelectedCursor = - - bold+reverse
TitleBar = ansi_81 - bold+reverse
OrderBar = ansi_244 ansi_235 -
OrderBarHighlight = ansi_244 ansi_235 bold+reverse
HelpBar = ansi_81 - bold+reverse
Prompt = ansi_208 - bold+reverse
NoticeInfo = - - bold
NoticeLoading = - - bold
NoticeError = ansi_199 - bold
NoticeSuccess = ansi_154 - bold
CursorBlock = ansi_252 - -
CursorBar1 = ansi_141 - -
CursorBar2 = ansi_197 - -
CursorBar3 = ansi_154 - -
CursorBar4 = ansi_208 - -
CommentAuthor = ansi_81 - -
CommentAuthorSelf = ansi_154 - -
CommentCount = - - -
CommentText = - - -
Created = - - -
Downvote = ansi_197 - bold
Gold = ansi_222 - bold
HiddenCommentExpand = ansi_244 - bold
HiddenCommentText = ansi_244 - -
MultiredditName = - - bold
MultiredditText = ansi_244 - -
NeutralVote = - - bold
NSFW = ansi_197 - bold+reverse
Saved = ansi_199 - -
Score = - - bold
Separator = ansi_241 - bold
Stickied = ansi_208 - -
SubscriptionName = - - bold
SubscriptionText = ansi_244 - -
SubmissionAuthor = ansi_154 - -
SubmissionFlair = ansi_197 - -
SubmissionSubreddit = ansi_222 - -
SubmissionText = - - -
SubmissionTitle = - - bold
Upvote = ansi_154 - bold
Link = ansi_67 - underline
LinkSeen = ansi_141 - underline
UserFlair = ansi_222 - bold

71
rtv/themes/papercolor.cfg Normal file
View File

@@ -0,0 +1,71 @@
# https://github.com/NLKNguyen/papercolor-theme
# background ansi_255
# negative ansi_124
# positive ansi_28
# olive ansi_64
# neutral ansi_31
# comment ansi_102
# navy ansi_24
# foreground ansi_238
# nontext ansi_250
# red ansi_160
# pink ansi_162
# purple ansi_91
# accent ansi_166
# orange ansi_166
# blue ansi_25
# highlight ansi_24
# aqua ansi_31
# green ansi_28
[theme]
;<element> = <foreground> <background> <attributes>
Normal = ansi_238 ansi_255 -
Selected = - ansi_254 -
SelectedCursor = - - bold+reverse
TitleBar = ansi_24 - bold+reverse
OrderBar = ansi_25 - bold
OrderBarHighlight = ansi_25 - bold+reverse
HelpBar = ansi_24 - bold+reverse
Prompt = ansi_31 - bold+reverse
NoticeInfo = ansi_238 ansi_252 bold
NoticeLoading = ansi_238 ansi_252 bold
NoticeError = ansi_124 ansi_225 bold
NoticeSuccess = ansi_28 ansi_157 bold
CursorBlock = ansi_102 - -
CursorBar1 = ansi_162 - -
CursorBar2 = ansi_166 - -
CursorBar3 = ansi_25 - -
CursorBar4 = ansi_91 - -
CommentAuthor = ansi_25 - bold
CommentAuthorSelf = ansi_64 - bold
CommentCount = - - -
CommentText = - - -
Created = - - -
Downvote = ansi_124 - bold
Gold = ansi_166 - bold
HiddenCommentExpand = ansi_102 - bold
HiddenCommentText = ansi_102 - -
MultiredditName = - - bold
MultiredditText = ansi_102 - -
NeutralVote = - - bold
NSFW = ansi_160 - bold+reverse
Saved = ansi_31 - bold
Score = - - bold
Separator = - - bold
Stickied = ansi_166 - bold
SubscriptionName = - - bold
SubscriptionText = ansi_102 - -
SubmissionAuthor = ansi_64 - bold
SubmissionFlair = ansi_162 - bold
SubmissionSubreddit = ansi_166 - bold
SubmissionText = - - -
SubmissionTitle = - - bold
Upvote = ansi_28 - bold
Link = ansi_24 - underline
LinkSeen = ansi_91 - underline
UserFlair = ansi_162 - bold

View File

@@ -23,10 +23,10 @@ Normal = ansi_244 ansi_234 -
Selected = ansi_244 ansi_235 - Selected = ansi_244 ansi_235 -
SelectedCursor = ansi_244 ansi_235 bold+reverse SelectedCursor = ansi_244 ansi_235 bold+reverse
PageTitle = ansi_37 - bold+reverse TitleBar = ansi_37 - bold+reverse
PageOrder = ansi_240 - bold OrderBar = ansi_245 - bold
PageOrderHighlight = ansi_240 - bold+reverse OrderBarHighlight = ansi_245 - bold+reverse
Help = ansi_37 - bold+reverse HelpBar = ansi_37 - bold+reverse
Prompt = ansi_33 - bold+reverse Prompt = ansi_33 - bold+reverse
NoticeInfo = - - bold NoticeInfo = - - bold
NoticeLoading = - - bold NoticeLoading = - - bold
@@ -46,18 +46,18 @@ CommentText = - - -
Created = - - - Created = - - -
Downvote = ansi_160 - bold Downvote = ansi_160 - bold
Gold = ansi_136 - bold Gold = ansi_136 - bold
HiddenCommentExpand = ansi_245 - bold HiddenCommentExpand = ansi_240 - bold
HiddenCommentText = ansi_245 - - HiddenCommentText = ansi_240 - -
MultiredditName = ansi_240 - bold MultiredditName = ansi_245 - bold
MultiredditText = ansi_245 - - MultiredditText = ansi_240 - -
NeutralVote = - - bold NeutralVote = - - bold
NSFW = ansi_125 - bold+reverse NSFW = ansi_160 - bold+reverse
Saved = ansi_125 - - Saved = ansi_125 - -
Score = - - - Score = - - -
Separator = - - bold Separator = - - bold
Stickied = ansi_136 - - Stickied = ansi_136 - -
SubscriptionName = ansi_240 - bold SubscriptionName = ansi_245 - bold
SubscriptionText = ansi_245 - - SubscriptionText = ansi_240 - -
SubmissionAuthor = ansi_64 - bold SubmissionAuthor = ansi_64 - bold
SubmissionFlair = ansi_160 - - SubmissionFlair = ansi_160 - -
SubmissionSubreddit = ansi_166 - - SubmissionSubreddit = ansi_166 - -

View File

@@ -21,12 +21,12 @@
;<element> = <foreground> <background> <attributes> ;<element> = <foreground> <background> <attributes>
Normal = ansi_241 ansi_230 - Normal = ansi_241 ansi_230 -
Selected = ansi_241 ansi_254 - Selected = ansi_241 ansi_254 -
SelectedCursor = ansi_241 ansi_254 reverse SelectedCursor = ansi_241 ansi_254 bold+reverse
PageTitle = ansi_37 - bold+reverse TitleBar = ansi_37 - bold+reverse
PageOrder = ansi_245 - bold OrderBar = ansi_245 - bold
PageOrderHighlight = ansi_245 - bold+reverse OrderBarHighlight = ansi_245 - bold+reverse
Help = ansi_37 - bold+reverse HelpBar = ansi_37 - bold+reverse
Prompt = ansi_33 - bold+reverse Prompt = ansi_33 - bold+reverse
NoticeInfo = - - bold NoticeInfo = - - bold
NoticeLoading = - - bold NoticeLoading = - - bold
@@ -34,10 +34,10 @@ NoticeError = ansi_160 - bold
NoticeSuccess = ansi_64 - bold NoticeSuccess = ansi_64 - bold
CursorBlock = ansi_245 - - CursorBlock = ansi_245 - -
CursorBar1 = ansi_125 - - CursorBar1 = ansi_125 - bold
CursorBar2 = ansi_160 - - CursorBar2 = ansi_160 - bold
CursorBar3 = ansi_61 - - CursorBar3 = ansi_61 - bold
CursorBar4 = ansi_37 - - CursorBar4 = ansi_37 - bold
CommentAuthor = ansi_33 - bold CommentAuthor = ansi_33 - bold
CommentAuthorSelf = ansi_64 - bold CommentAuthorSelf = ansi_64 - bold
@@ -51,16 +51,16 @@ HiddenCommentText = ansi_245 - -
MultiredditName = ansi_240 - bold MultiredditName = ansi_240 - bold
MultiredditText = ansi_245 - - MultiredditText = ansi_245 - -
NeutralVote = - - bold NeutralVote = - - bold
NSFW = ansi_125 - bold+reverse NSFW = ansi_160 - bold+reverse
Saved = ansi_125 - - Saved = ansi_125 - bold
Score = - - - Score = - - -
Separator = - - bold Separator = - - bold
Stickied = ansi_136 - - Stickied = ansi_136 - bold
SubscriptionName = ansi_240 - bold SubscriptionName = ansi_240 - bold
SubscriptionText = ansi_245 - - SubscriptionText = ansi_245 - -
SubmissionAuthor = ansi_64 - bold SubmissionAuthor = ansi_64 - bold
SubmissionFlair = ansi_160 - - SubmissionFlair = ansi_160 - bold
SubmissionSubreddit = ansi_166 - - SubmissionSubreddit = ansi_166 - bold
SubmissionText = - - - SubmissionText = - - -
SubmissionTitle = ansi_240 - bold SubmissionTitle = ansi_240 - bold
Upvote = ansi_64 - bold Upvote = ansi_64 - bold

View File

@@ -7,6 +7,7 @@ import os
import sys import sys
import time import time
import curses import curses
import locale
import threading import threading
from types import MethodType from types import MethodType
from collections import Counter from collections import Counter
@@ -14,7 +15,7 @@ from collections import Counter
from vcr import VCR from vcr import VCR
from six.moves.urllib.parse import urlparse, parse_qs from six.moves.urllib.parse import urlparse, parse_qs
from rtv.theme import ThemeList from rtv.theme import Theme, get_next_theme, get_previous_theme, theme_list
from rtv.config import Config from rtv.config import Config
from rtv.packages import praw from rtv.packages import praw
from rtv.oauth import OAuthHelper from rtv.oauth import OAuthHelper
@@ -151,7 +152,7 @@ def draw_screen(stdscr, reddit, config, theme, oauth):
term.getch = MethodType(notification_getch, term) term.getch = MethodType(notification_getch, term)
thread = threading.Thread(target=term.show_notification, thread = threading.Thread(target=term.show_notification,
args=('Success',), args=('Success',),
kwargs={'style': 'success'}) kwargs={'style': 'Success'})
thread.start() thread.start()
threads.append((thread, term)) threads.append((thread, term))
@@ -172,7 +173,7 @@ def draw_screen(stdscr, reddit, config, theme, oauth):
term.getch = MethodType(notification_getch, term) term.getch = MethodType(notification_getch, term)
thread = threading.Thread(target=term.show_notification, thread = threading.Thread(target=term.show_notification,
args=('Error',), args=('Error',),
kwargs={'style': 'error'}) kwargs={'style': 'Error'})
thread.start() thread.start()
threads.append((thread, term)) threads.append((thread, term))
@@ -193,7 +194,7 @@ def draw_screen(stdscr, reddit, config, theme, oauth):
term.getch = MethodType(notification_getch, term) term.getch = MethodType(notification_getch, term)
thread = threading.Thread(target=term.show_notification, thread = threading.Thread(target=term.show_notification,
args=('Info',), args=('Info',),
kwargs={'style': 'info'}) kwargs={'style': 'Info'})
thread.start() thread.start()
threads.append((thread, term)) threads.append((thread, term))
@@ -212,14 +213,12 @@ def draw_screen(stdscr, reddit, config, theme, oauth):
def main(): def main():
if len(sys.argv) > 1: locale.setlocale(locale.LC_ALL, '')
current_theme = sys.argv[1]
else:
current_theme = None
theme_list = ThemeList(current_theme) if len(sys.argv) > 1:
theme_list.load() theme = Theme.from_name(sys.argv[1])
theme = theme_list.current_theme else:
theme = Theme()
vcr = initialize_vcr() vcr = initialize_vcr()
with vcr.use_cassette('demo_theme.yaml') as cassette, \ with vcr.use_cassette('demo_theme.yaml') as cassette, \
@@ -234,6 +233,7 @@ def main():
reddit = praw.Reddit(user_agent='RTV Theme Demo', reddit = praw.Reddit(user_agent='RTV Theme Demo',
decode_html_entities=False, decode_html_entities=False,
disable_update_check=True) disable_update_check=True)
reddit.config.api_request_delay = 0
config.history.add('https://api.reddit.com/comments/6llvsl/_/djutc3s') config.history.add('https://api.reddit.com/comments/6llvsl/_/djutc3s')
config.history.add('http://i.imgur.com/Z9iGKWv.gifv') config.history.add('http://i.imgur.com/Z9iGKWv.gifv')
@@ -245,7 +245,6 @@ def main():
oauth.authorize() oauth.authorize()
while True: while True:
term = Terminal(stdscr, config) term = Terminal(stdscr, config)
term.set_theme(theme) term.set_theme(theme)
threads = draw_screen(stdscr, reddit, config, theme, oauth) threads = draw_screen(stdscr, reddit, config, theme, oauth)
@@ -264,12 +263,17 @@ def main():
else: else:
cassette.play_counts = Counter() cassette.play_counts = Counter()
theme_list.reload()
if ch == curses.KEY_RIGHT: if ch == curses.KEY_RIGHT:
theme = theme_list.next() theme = get_next_theme(theme)
elif ch == curses.KEY_LEFT: elif ch == curses.KEY_LEFT:
theme = theme_list.previous() theme = get_previous_theme(theme)
elif ch == Terminal.ESCAPE: elif ch == Terminal.ESCAPE:
break break
else:
# Force the theme to reload
theme = get_next_theme(theme)
theme = get_previous_theme(theme)
sys.exit(main()) sys.exit(main())