From f5391e088dc6a68f76cd49f5a486ccbf4025ccae Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Thu, 5 Feb 2015 22:59:08 -0800 Subject: [PATCH] Minor refactoring, tweaked color schemes. --- main.py | 1 - rtv/content.py | 22 +++++++++++----------- rtv/submission.py | 25 +++++++++++++++---------- rtv/subreddit.py | 13 +++++++++---- rtv/utils.py | 1 + 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/main.py b/main.py index b9bb3da..839b911 100644 --- a/main.py +++ b/main.py @@ -29,7 +29,6 @@ def main(): with curses_session() as stdscr: if args.link: - # Go directly to submission page = SubmissionPage(stdscr, reddit, url=args.link) page.loop() diff --git a/rtv/content.py b/rtv/content.py index 5833ee9..f903c5b 100644 --- a/rtv/content.py +++ b/rtv/content.py @@ -167,13 +167,12 @@ class SubmissionContent(BaseContent): self.indent_size = indent_size self.max_indent_level = max_indent_level self._loader = loader - self._submission = submission - self._submission_data = self.strip_praw_submission(submission) - self.name = self._submission_data['permalink'] - with self._loader(): - comments = self.flatten_comments(submission.comments) - self._comment_data = [self.strip_praw_comment(c) for c in comments] + self._submission_data = None + self._comment_data = None + self.name = None + + self.reset() @classmethod def from_url( @@ -195,11 +194,12 @@ class SubmissionContent(BaseContent): def reset(self): - self._submission.refresh() - self._submission_data = self.strip_praw_submission(submission) - self.name = self._submission_data['permalink'] - comments = self.flatten_comments(submission.comments) - self._comment_data = [self.strip_praw_comment(c) for c in comments] + with self._loader(): + self._submission.refresh() + self._submission_data = self.strip_praw_submission(self._submission) + self.name = self._submission_data['permalink'] + comments = self.flatten_comments(self._submission.comments) + self._comment_data = [self.strip_praw_comment(c) for c in comments] def get(self, index, n_cols=70): """ diff --git a/rtv/submission.py b/rtv/submission.py index 8019030..7987340 100644 --- a/rtv/submission.py +++ b/rtv/submission.py @@ -41,7 +41,7 @@ class SubmissionPage(BasePage): self.refresh_content() # Show / hide a comment tree - elif cmd == ord(' '): + elif cmd in (curses.KEY_RIGHT, ord(' ')): self.toggle_comment() elif cmd == curses.KEY_RESIZE: @@ -126,10 +126,10 @@ class SubmissionPage(BasePage): n_rows, n_cols = win.getmaxyx() n_cols -= 1 - win.addnstr(0, 1, data['body'], n_cols-1) + text = '{body}'.format(**data) + win.addnstr(0, 1, text, n_cols-1) text = ' [{count}]'.format(**data) - attr = curses.A_BOLD - win.addnstr(text, n_cols - win.getyx()[1], attr) + win.addnstr(text, n_cols - win.getyx()[1], curses.A_BOLD) attr = Color.get_level(data['level']) for y in range(n_rows): @@ -147,21 +147,26 @@ class SubmissionPage(BasePage): return for row, text in enumerate(data['split_title'], start=1): - win.addnstr(row, 1, text, n_cols) + win.addnstr(row, 1, text, n_cols, curses.A_BOLD) - text = '{} {} {}'.format(data['author'], data['created'], data['subreddit']) row = len(data['split_title']) + 1 - win.addnstr(row, 1, text, n_cols) + attr = curses.A_BOLD | Color.GREEN + text = '{author}'.format(**data) + win.addnstr(row, 1, text, n_cols, attr) + text = ' {created} {subreddit}'.format(**data) + win.addnstr(text, n_cols - win.getyx()[1]) row = len(data['split_title']) + 2 - win.addnstr(row, 1, data['url'], n_cols) + attr = curses.A_UNDERLINE | Color.BLUE + text = '{url}'.format(**data) + win.addnstr(row, 1, text, n_cols, attr) offset = len(data['split_title']) + 3 for row, text in enumerate(data['split_text'], start=offset): win.addnstr(row, 1, text, n_cols) - text = '{} {}'.format(data['score'], data['comments']) row = len(data['split_title']) + len(data['split_text']) + 3 - win.addnstr(row, 1, text, n_cols) + text = '{} {}'.format(data['score'], data['comments']) + win.addnstr(row, 1, text, n_cols, curses.A_BOLD) win.border() \ No newline at end of file diff --git a/rtv/subreddit.py b/rtv/subreddit.py index 53e04ef..234babb 100644 --- a/rtv/subreddit.py +++ b/rtv/subreddit.py @@ -99,7 +99,7 @@ class SubredditPage(BasePage): def draw_item(win, data, inverted=False): n_rows, n_cols = win.getmaxyx() - n_cols -= 2 # Leave space for the cursor in the first column + n_cols -= 1 # Leave space for the cursor in the first column # Handle the case where the window is not large enough to fit the data. valid_rows = range(0, n_rows) @@ -114,12 +114,17 @@ class SubredditPage(BasePage): row = n_title + offset if row in valid_rows: attr = curses.A_UNDERLINE | Color.BLUE - win.addnstr(row, 1, '{url}'.format(**data), n_cols, attr) + text = '{url}'.format(**data) + win.addnstr(row, 1, text, n_cols-1, attr) row = n_title + offset + 1 if row in valid_rows: - win.addnstr(row, 1, '{created} {comments} {score}'.format(**data), n_cols) + text = '{created} {comments} {score}'.format(**data) + win.addnstr(row, 1, text, n_cols-1) row = n_title + offset + 2 if row in valid_rows: - win.addnstr(row, 1, '{author} {subreddit}'.format(**data), n_cols) \ No newline at end of file + text = '{author}'.format(**data) + win.addnstr(row, 1, text, n_cols-1, curses.A_BOLD) + text = ' {subreddit}'.format(**data) + win.addnstr(text, n_cols - win.getyx()[1], Color.YELLOW) \ No newline at end of file diff --git a/rtv/utils.py b/rtv/utils.py index e8c3462..cd3b247 100644 --- a/rtv/utils.py +++ b/rtv/utils.py @@ -16,6 +16,7 @@ class Color(object): 'BLUE': (curses.COLOR_BLUE, -1), 'MAGENTA': (curses.COLOR_MAGENTA, -1), 'CYAN': (curses.COLOR_CYAN, -1), + 'WHITE': (curses.COLOR_WHITE, -1), } @classmethod