Merge pull request #302 from alx-k/master
Setting the maximum comment column width
This commit is contained in:
@@ -240,8 +240,10 @@ class Config(object):
|
||||
'enable_media': partial(config.getboolean, 'rtv'),
|
||||
'history_size': partial(config.getint, 'rtv'),
|
||||
'oauth_redirect_port': partial(config.getint, 'rtv'),
|
||||
'oauth_scope': lambda x: rtv[x].split(',')
|
||||
'oauth_scope': lambda x: rtv[x].split(','),
|
||||
'max_comment_cols': partial(config.getint, 'rtv')
|
||||
}
|
||||
|
||||
for key, func in params.items():
|
||||
if key in rtv:
|
||||
rtv[key] = func(key)
|
||||
|
||||
@@ -295,7 +295,7 @@ class SubmissionContent(Content):
|
||||
"""
|
||||
|
||||
def __init__(self, submission, loader, indent_size=2, max_indent_level=8,
|
||||
order=None):
|
||||
order=None, max_comment_cols=120):
|
||||
|
||||
submission_data = self.strip_praw_submission(submission)
|
||||
comments = self.flatten_comments(submission.comments)
|
||||
@@ -308,17 +308,19 @@ class SubmissionContent(Content):
|
||||
self._submission = submission
|
||||
self._submission_data = submission_data
|
||||
self._comment_data = [self.strip_praw_comment(c) for c in comments]
|
||||
self._max_comment_cols = max_comment_cols
|
||||
|
||||
@classmethod
|
||||
def from_url(cls, reddit, url, loader, indent_size=2, max_indent_level=8,
|
||||
order=None):
|
||||
order=None, max_comment_cols=120):
|
||||
|
||||
url = url.replace('http:', 'https:') # Reddit forces SSL
|
||||
# Sometimes reddit will return a 403 FORBIDDEN when trying to access an
|
||||
# np link while using OAUTH. Cause is unknown.
|
||||
url = url.replace('https://np.', 'https://www.')
|
||||
submission = reddit.get_submission(url, comment_sort=order)
|
||||
return cls(submission, loader, indent_size, max_indent_level, order)
|
||||
return cls(submission, loader, indent_size, max_indent_level, order,
|
||||
max_comment_cols)
|
||||
|
||||
@property
|
||||
def range(self):
|
||||
@@ -346,7 +348,7 @@ class SubmissionContent(Content):
|
||||
data['offset'] = indent_level * self.indent_size
|
||||
|
||||
if data['type'] == 'Comment':
|
||||
width = n_cols - data['offset']
|
||||
width = min(n_cols - data['offset'], self._max_comment_cols)
|
||||
data['split_body'] = self.wrap_text(data['body'], width=width)
|
||||
data['n_rows'] = len(data['split_body']) + 1
|
||||
else:
|
||||
|
||||
@@ -23,10 +23,15 @@ class SubmissionPage(Page):
|
||||
super(SubmissionPage, self).__init__(reddit, term, config, oauth)
|
||||
|
||||
self.controller = SubmissionController(self, keymap=config.keymap)
|
||||
|
||||
if url:
|
||||
self.content = SubmissionContent.from_url(reddit, url, term.loader)
|
||||
self.content = SubmissionContent.from_url(
|
||||
reddit, url, term.loader,
|
||||
max_comment_cols=config['max_comment_cols'])
|
||||
else:
|
||||
self.content = SubmissionContent(submission, term.loader)
|
||||
self.content = SubmissionContent(
|
||||
submission, term.loader,
|
||||
max_comment_cols=config['max_comment_cols'])
|
||||
# Start at the submission post, which is indexed as -1
|
||||
self.nav = Navigator(self.content.get, page_index=-1)
|
||||
self.selected_subreddit = None
|
||||
@@ -66,7 +71,8 @@ class SubmissionPage(Page):
|
||||
|
||||
with self.term.loader('Refreshing page'):
|
||||
self.content = SubmissionContent.from_url(
|
||||
self.reddit, url, self.term.loader, order=order)
|
||||
self.reddit, url, self.term.loader, order=order,
|
||||
max_comment_cols=self.config['max_comment_cols'])
|
||||
if not self.term.loader.exception:
|
||||
self.nav = Navigator(self.content.get, page_index=-1)
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ class SubredditPage(Page):
|
||||
|
||||
# Check that the subreddit can be submitted to
|
||||
name = self.content.name
|
||||
if '+' in name or name in ('/r/all', '/r/front', '/r/me','/u/saved'):
|
||||
if '+' in name or name in ('/r/all', '/r/front', '/r/me', '/u/saved'):
|
||||
self.term.show_notification("Can't post to {0}".format(name))
|
||||
return
|
||||
|
||||
@@ -272,4 +272,4 @@ class SubredditPage(Page):
|
||||
self.term.add_line(win, text, attr=Color.YELLOW)
|
||||
if data['flair']:
|
||||
text = ' {flair}'.format(**data)
|
||||
self.term.add_line(win, text, attr=Color.RED)
|
||||
self.term.add_line(win, text, attr=Color.RED)
|
||||
@@ -37,6 +37,9 @@ history_size = 200
|
||||
; Open external links using programs defined in the mailcap config.
|
||||
enable_media = False
|
||||
|
||||
; Maximum number of columns for a comment
|
||||
max_comment_cols = 120
|
||||
|
||||
################
|
||||
# OAuth Settings
|
||||
################
|
||||
|
||||
Reference in New Issue
Block a user