Minor refactoring, tweaked color schemes.
This commit is contained in:
1
main.py
1
main.py
@@ -29,7 +29,6 @@ def main():
|
|||||||
with curses_session() as stdscr:
|
with curses_session() as stdscr:
|
||||||
|
|
||||||
if args.link:
|
if args.link:
|
||||||
# Go directly to submission
|
|
||||||
page = SubmissionPage(stdscr, reddit, url=args.link)
|
page = SubmissionPage(stdscr, reddit, url=args.link)
|
||||||
page.loop()
|
page.loop()
|
||||||
|
|
||||||
|
|||||||
@@ -167,13 +167,12 @@ class SubmissionContent(BaseContent):
|
|||||||
self.indent_size = indent_size
|
self.indent_size = indent_size
|
||||||
self.max_indent_level = max_indent_level
|
self.max_indent_level = max_indent_level
|
||||||
self._loader = loader
|
self._loader = loader
|
||||||
|
|
||||||
self._submission = submission
|
self._submission = submission
|
||||||
self._submission_data = self.strip_praw_submission(submission)
|
self._submission_data = None
|
||||||
self.name = self._submission_data['permalink']
|
self._comment_data = None
|
||||||
with self._loader():
|
self.name = None
|
||||||
comments = self.flatten_comments(submission.comments)
|
|
||||||
self._comment_data = [self.strip_praw_comment(c) for c in comments]
|
self.reset()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_url(
|
def from_url(
|
||||||
@@ -195,10 +194,11 @@ class SubmissionContent(BaseContent):
|
|||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
|
|
||||||
|
with self._loader():
|
||||||
self._submission.refresh()
|
self._submission.refresh()
|
||||||
self._submission_data = self.strip_praw_submission(submission)
|
self._submission_data = self.strip_praw_submission(self._submission)
|
||||||
self.name = self._submission_data['permalink']
|
self.name = self._submission_data['permalink']
|
||||||
comments = self.flatten_comments(submission.comments)
|
comments = self.flatten_comments(self._submission.comments)
|
||||||
self._comment_data = [self.strip_praw_comment(c) for c in comments]
|
self._comment_data = [self.strip_praw_comment(c) for c in comments]
|
||||||
|
|
||||||
def get(self, index, n_cols=70):
|
def get(self, index, n_cols=70):
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class SubmissionPage(BasePage):
|
|||||||
self.refresh_content()
|
self.refresh_content()
|
||||||
|
|
||||||
# Show / hide a comment tree
|
# Show / hide a comment tree
|
||||||
elif cmd == ord(' '):
|
elif cmd in (curses.KEY_RIGHT, ord(' ')):
|
||||||
self.toggle_comment()
|
self.toggle_comment()
|
||||||
|
|
||||||
elif cmd == curses.KEY_RESIZE:
|
elif cmd == curses.KEY_RESIZE:
|
||||||
@@ -126,10 +126,10 @@ class SubmissionPage(BasePage):
|
|||||||
|
|
||||||
n_rows, n_cols = win.getmaxyx()
|
n_rows, n_cols = win.getmaxyx()
|
||||||
n_cols -= 1
|
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)
|
text = ' [{count}]'.format(**data)
|
||||||
attr = curses.A_BOLD
|
win.addnstr(text, n_cols - win.getyx()[1], curses.A_BOLD)
|
||||||
win.addnstr(text, n_cols - win.getyx()[1], attr)
|
|
||||||
|
|
||||||
attr = Color.get_level(data['level'])
|
attr = Color.get_level(data['level'])
|
||||||
for y in range(n_rows):
|
for y in range(n_rows):
|
||||||
@@ -147,21 +147,26 @@ class SubmissionPage(BasePage):
|
|||||||
return
|
return
|
||||||
|
|
||||||
for row, text in enumerate(data['split_title'], start=1):
|
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
|
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
|
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
|
offset = len(data['split_title']) + 3
|
||||||
for row, text in enumerate(data['split_text'], start=offset):
|
for row, text in enumerate(data['split_text'], start=offset):
|
||||||
win.addnstr(row, 1, text, n_cols)
|
win.addnstr(row, 1, text, n_cols)
|
||||||
|
|
||||||
text = '{} {}'.format(data['score'], data['comments'])
|
|
||||||
row = len(data['split_title']) + len(data['split_text']) + 3
|
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()
|
win.border()
|
||||||
@@ -99,7 +99,7 @@ class SubredditPage(BasePage):
|
|||||||
def draw_item(win, data, inverted=False):
|
def draw_item(win, data, inverted=False):
|
||||||
|
|
||||||
n_rows, n_cols = win.getmaxyx()
|
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.
|
# Handle the case where the window is not large enough to fit the data.
|
||||||
valid_rows = range(0, n_rows)
|
valid_rows = range(0, n_rows)
|
||||||
@@ -114,12 +114,17 @@ class SubredditPage(BasePage):
|
|||||||
row = n_title + offset
|
row = n_title + offset
|
||||||
if row in valid_rows:
|
if row in valid_rows:
|
||||||
attr = curses.A_UNDERLINE | Color.BLUE
|
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
|
row = n_title + offset + 1
|
||||||
if row in valid_rows:
|
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
|
row = n_title + offset + 2
|
||||||
if row in valid_rows:
|
if row in valid_rows:
|
||||||
win.addnstr(row, 1, '{author} {subreddit}'.format(**data), n_cols)
|
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)
|
||||||
@@ -16,6 +16,7 @@ class Color(object):
|
|||||||
'BLUE': (curses.COLOR_BLUE, -1),
|
'BLUE': (curses.COLOR_BLUE, -1),
|
||||||
'MAGENTA': (curses.COLOR_MAGENTA, -1),
|
'MAGENTA': (curses.COLOR_MAGENTA, -1),
|
||||||
'CYAN': (curses.COLOR_CYAN, -1),
|
'CYAN': (curses.COLOR_CYAN, -1),
|
||||||
|
'WHITE': (curses.COLOR_WHITE, -1),
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user