From aa9ec95da4387fd15a2c885882106c1df182aee6 Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Tue, 27 Jan 2015 00:18:19 -0800 Subject: [PATCH] Populated submission box in submission viewer. --- rtv/content_generators.py | 5 +++-- rtv/submission_viewer.py | 24 ++++++++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/rtv/content_generators.py b/rtv/content_generators.py index d352bc2..d335e9a 100644 --- a/rtv/content_generators.py +++ b/rtv/content_generators.py @@ -181,8 +181,9 @@ class SubmissionContent(BaseContent): elif index == -1: data = self._submission_data - data['split_title'] = textwrap.wrap(data['title'], width=n_cols) - data['n_rows'] = len(data['split_title']) + 3 + data['split_title'] = textwrap.wrap(data['title'], width=n_cols-2) + data['split_text'] = textwrap.wrap(data['text'], width=n_cols-2) + data['n_rows'] = (len(data['split_title']) + len(data['split_text']) + 5) data['offset'] = 0 else: diff --git a/rtv/submission_viewer.py b/rtv/submission_viewer.py index a151b7d..edbced8 100644 --- a/rtv/submission_viewer.py +++ b/rtv/submission_viewer.py @@ -104,14 +104,30 @@ class SubmissionViewer(BaseViewer): def draw_submission(win, data): n_rows, n_cols = win.getmaxyx() - n_cols -= 1 - - # Don't print anything if there is not enough room + n_cols -= 3 # one for each side of the border + one for offset + # Don't print at all if there is not enough room to fit the whole sub if data['n_rows'] > n_rows: return - win.border() + for row, text in enumerate(data['split_title'], start=1): + win.addnstr(row, 1, text, n_cols) + text = '{} {} {}'.format(data['author'], data['created'], data['subreddit']) + row = len(data['split_title']) + 1 + win.addnstr(row, 1, text, n_cols) + + row = len(data['split_title']) + 2 + win.addnstr(row, 1, data['url'], n_cols) + + 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) + + win.border() def main():