Adding the ability to highlight
This commit is contained in:
@@ -199,18 +199,16 @@ class SubmissionPage(Page):
|
||||
else:
|
||||
self.term.flash()
|
||||
|
||||
def _draw_item(self, win, data, inverted):
|
||||
def _draw_item(self, win, data, inverted, highlight):
|
||||
|
||||
if data['type'] == 'MoreComments':
|
||||
return self._draw_more_comments(win, data)
|
||||
elif data['type'] == 'HiddenComment':
|
||||
return self._draw_more_comments(win, data)
|
||||
if data['type'] in ('MoreComments', 'HiddenComment'):
|
||||
self._draw_more_comments(win, data, highlight)
|
||||
elif data['type'] == 'Comment':
|
||||
return self._draw_comment(win, data, inverted)
|
||||
self._draw_comment(win, data, inverted, highlight)
|
||||
else:
|
||||
return self._draw_submission(win, data)
|
||||
self._draw_submission(win, data, highlight)
|
||||
|
||||
def _draw_comment(self, win, data, inverted):
|
||||
def _draw_comment(self, win, data, inverted, highlight):
|
||||
|
||||
n_rows, n_cols = win.getmaxyx()
|
||||
n_cols -= 1
|
||||
@@ -232,105 +230,102 @@ class SubmissionPage(Page):
|
||||
row = offset
|
||||
if row in valid_rows:
|
||||
if data['is_author']:
|
||||
attr = self.term.attr('comment_author_self')
|
||||
attr = self.term.attr('comment_author_self', highlight)
|
||||
else:
|
||||
attr = self.term.attr('comment_author')
|
||||
attr = self.term.attr('comment_author', highlight)
|
||||
self.term.add_line(win, '{author}'.format(**data), row, 1, attr)
|
||||
|
||||
if data['flair']:
|
||||
attr = self.term.attr('user_flair')
|
||||
attr = self.term.attr('user_flair', highlight)
|
||||
self.term.add_space(win)
|
||||
self.term.add_line(win, '{flair}'.format(**data), attr=attr)
|
||||
|
||||
arrow, attr = self.term.get_arrow(data['likes'])
|
||||
arrow, attr = self.term.get_arrow(data['likes'], highlight)
|
||||
self.term.add_space(win)
|
||||
self.term.add_line(win, arrow, attr=attr)
|
||||
|
||||
attr = self.term.attr('score')
|
||||
attr = self.term.attr('score', highlight)
|
||||
self.term.add_space(win)
|
||||
self.term.add_line(win, '{score}'.format(**data), attr=attr)
|
||||
|
||||
attr = self.term.attr('created')
|
||||
attr = self.term.attr('created', highlight)
|
||||
self.term.add_space(win)
|
||||
self.term.add_line(win, '{created}'.format(**data), attr=attr)
|
||||
|
||||
if data['gold']:
|
||||
attr = self.term.attr('gold')
|
||||
attr = self.term.attr('gold', highlight)
|
||||
self.term.add_space(win)
|
||||
self.term.add_line(win, self.term.guilded, attr=attr)
|
||||
|
||||
if data['stickied']:
|
||||
attr = self.term.attr('stickied')
|
||||
attr = self.term.attr('stickied', highlight)
|
||||
self.term.add_space(win)
|
||||
self.term.add_line(win, '[stickied]', attr=attr)
|
||||
|
||||
if data['saved']:
|
||||
attr = self.term.attr('saved')
|
||||
attr = self.term.attr('saved', highlight)
|
||||
self.term.add_space(win)
|
||||
self.term.add_line(win, '[saved]', attr=attr)
|
||||
|
||||
for row, text in enumerate(split_body, start=offset+1):
|
||||
attr = self.term.attr('comment_text')
|
||||
attr = self.term.attr('comment_text', highlight)
|
||||
if row in valid_rows:
|
||||
self.term.add_line(win, text, row, 1, attr=attr)
|
||||
|
||||
# Unfortunately vline() doesn't support custom color so we have to
|
||||
# build it one segment at a time.
|
||||
attr = self.term.theme.get_bar_level(data['level'])
|
||||
x = 0
|
||||
index = data['level'] % len(self.term.theme.BAR_LEVELS)
|
||||
attr = self.term.attr(self.term.theme.BAR_LEVELS[index], highlight)
|
||||
for y in range(n_rows):
|
||||
self.term.addch(win, y, x, self.term.vline, attr)
|
||||
self.term.addch(win, y, 0, self.term.vline, attr)
|
||||
|
||||
return attr | self.term.vline
|
||||
|
||||
def _draw_more_comments(self, win, data):
|
||||
def _draw_more_comments(self, win, data, highlight):
|
||||
|
||||
n_rows, n_cols = win.getmaxyx()
|
||||
n_cols -= 1
|
||||
|
||||
attr = self.term.attr('hidden_comment_text')
|
||||
attr = self.term.attr('hidden_comment_text', highlight)
|
||||
self.term.add_line(win, '{body}'.format(**data), 0, 1, attr=attr)
|
||||
|
||||
attr = self.term.attr('hidden_comment_expand')
|
||||
attr = self.term.attr('hidden_comment_expand', highlight)
|
||||
self.term.add_space(win)
|
||||
self.term.add_line(win, '[{count}]'.format(**data), attr=attr)
|
||||
|
||||
attr = self.term.theme.get_bar_level(data['level'])
|
||||
index = data['level'] % len(self.term.theme.BAR_LEVELS)
|
||||
attr = self.term.attr(self.term.theme.BAR_LEVELS[index], highlight)
|
||||
self.term.addch(win, 0, 0, self.term.vline, attr)
|
||||
|
||||
return attr | self.term.vline
|
||||
|
||||
def _draw_submission(self, win, data):
|
||||
def _draw_submission(self, win, data, highlight):
|
||||
|
||||
n_rows, n_cols = win.getmaxyx()
|
||||
n_cols -= 3 # one for each side of the border + one for offset
|
||||
|
||||
attr = self.term.attr('submission_title')
|
||||
attr = self.term.attr('submission_title', highlight)
|
||||
for row, text in enumerate(data['split_title'], start=1):
|
||||
self.term.add_line(win, text, row, 1, attr)
|
||||
|
||||
row = len(data['split_title']) + 1
|
||||
attr = self.term.attr('submission_author')
|
||||
attr = self.term.attr('submission_author', highlight)
|
||||
self.term.add_line(win, '{author}'.format(**data), row, 1, attr)
|
||||
|
||||
if data['flair']:
|
||||
attr = self.term.attr('submission_flair')
|
||||
attr = self.term.attr('submission_flair', highlight)
|
||||
self.term.add_space(win)
|
||||
self.term.add_line(win, '{flair}'.format(**data), attr=attr)
|
||||
|
||||
attr = self.term.attr('created')
|
||||
attr = self.term.attr('created', highlight)
|
||||
self.term.add_space(win)
|
||||
self.term.add_line(win, '{created}'.format(**data), attr=attr)
|
||||
|
||||
attr = self.term.attr('submission_subreddit')
|
||||
attr = self.term.attr('submission_subreddit', highlight)
|
||||
self.term.add_space(win)
|
||||
self.term.add_line(win, '/r/{subreddit}'.format(**data), attr=attr)
|
||||
|
||||
row = len(data['split_title']) + 2
|
||||
if data['url_full'] in self.config.history:
|
||||
attr = self.term.attr('url_seen')
|
||||
attr = self.term.attr('url_seen', highlight)
|
||||
else:
|
||||
attr = self.term.attr('url')
|
||||
attr = self.term.attr('url', highlight)
|
||||
self.term.add_line(win, '{url}'.format(**data), row, 1, attr)
|
||||
|
||||
offset = len(data['split_title']) + 3
|
||||
@@ -342,34 +337,34 @@ class SubmissionPage(Page):
|
||||
split_text = split_text[:-cutoff]
|
||||
split_text.append('(Not enough space to display)')
|
||||
|
||||
attr = self.term.attr('submission_text')
|
||||
attr = self.term.attr('submission_text', highlight)
|
||||
for row, text in enumerate(split_text, start=offset):
|
||||
self.term.add_line(win, text, row, 1, attr=attr)
|
||||
|
||||
row = len(data['split_title']) + len(split_text) + 3
|
||||
attr = self.term.attr('score')
|
||||
attr = self.term.attr('score', highlight)
|
||||
self.term.add_line(win, '{score}'.format(**data), row, 1, attr=attr)
|
||||
|
||||
arrow, attr = self.term.get_arrow(data['likes'])
|
||||
arrow, attr = self.term.get_arrow(data['likes'], highlight)
|
||||
self.term.add_space(win)
|
||||
self.term.add_line(win, arrow, attr=attr)
|
||||
|
||||
attr = self.term.attr('comment_count')
|
||||
attr = self.term.attr('comment_count', highlight)
|
||||
self.term.add_space(win)
|
||||
self.term.add_line(win, '{comments}'.format(**data), attr=attr)
|
||||
|
||||
if data['gold']:
|
||||
attr = self.term.attr('gold')
|
||||
attr = self.term.attr('gold', highlight)
|
||||
self.term.add_space(win)
|
||||
self.term.add_line(win, self.term.guilded, attr=attr)
|
||||
|
||||
if data['nsfw']:
|
||||
attr = self.term.attr('nsfw')
|
||||
attr = self.term.attr('nsfw', highlight)
|
||||
self.term.add_space(win)
|
||||
self.term.add_line(win, 'NSFW', attr=attr)
|
||||
|
||||
if data['saved']:
|
||||
attr = self.term.attr('saved')
|
||||
attr = self.term.attr('saved', highlight)
|
||||
self.term.add_space(win)
|
||||
self.term.add_line(win, '[saved]', attr=attr)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user