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'),
|
'enable_media': partial(config.getboolean, 'rtv'),
|
||||||
'history_size': partial(config.getint, 'rtv'),
|
'history_size': partial(config.getint, 'rtv'),
|
||||||
'oauth_redirect_port': 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():
|
for key, func in params.items():
|
||||||
if key in rtv:
|
if key in rtv:
|
||||||
rtv[key] = func(key)
|
rtv[key] = func(key)
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ class SubmissionContent(Content):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, submission, loader, indent_size=2, max_indent_level=8,
|
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)
|
submission_data = self.strip_praw_submission(submission)
|
||||||
comments = self.flatten_comments(submission.comments)
|
comments = self.flatten_comments(submission.comments)
|
||||||
@@ -308,17 +308,19 @@ class SubmissionContent(Content):
|
|||||||
self._submission = submission
|
self._submission = submission
|
||||||
self._submission_data = submission_data
|
self._submission_data = submission_data
|
||||||
self._comment_data = [self.strip_praw_comment(c) for c in comments]
|
self._comment_data = [self.strip_praw_comment(c) for c in comments]
|
||||||
|
self._max_comment_cols = max_comment_cols
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_url(cls, reddit, url, loader, indent_size=2, max_indent_level=8,
|
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
|
url = url.replace('http:', 'https:') # Reddit forces SSL
|
||||||
# Sometimes reddit will return a 403 FORBIDDEN when trying to access an
|
# Sometimes reddit will return a 403 FORBIDDEN when trying to access an
|
||||||
# np link while using OAUTH. Cause is unknown.
|
# np link while using OAUTH. Cause is unknown.
|
||||||
url = url.replace('https://np.', 'https://www.')
|
url = url.replace('https://np.', 'https://www.')
|
||||||
submission = reddit.get_submission(url, comment_sort=order)
|
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
|
@property
|
||||||
def range(self):
|
def range(self):
|
||||||
@@ -346,7 +348,7 @@ class SubmissionContent(Content):
|
|||||||
data['offset'] = indent_level * self.indent_size
|
data['offset'] = indent_level * self.indent_size
|
||||||
|
|
||||||
if data['type'] == 'Comment':
|
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['split_body'] = self.wrap_text(data['body'], width=width)
|
||||||
data['n_rows'] = len(data['split_body']) + 1
|
data['n_rows'] = len(data['split_body']) + 1
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -23,10 +23,15 @@ class SubmissionPage(Page):
|
|||||||
super(SubmissionPage, self).__init__(reddit, term, config, oauth)
|
super(SubmissionPage, self).__init__(reddit, term, config, oauth)
|
||||||
|
|
||||||
self.controller = SubmissionController(self, keymap=config.keymap)
|
self.controller = SubmissionController(self, keymap=config.keymap)
|
||||||
|
|
||||||
if url:
|
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:
|
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
|
# Start at the submission post, which is indexed as -1
|
||||||
self.nav = Navigator(self.content.get, page_index=-1)
|
self.nav = Navigator(self.content.get, page_index=-1)
|
||||||
self.selected_subreddit = None
|
self.selected_subreddit = None
|
||||||
@@ -66,7 +71,8 @@ class SubmissionPage(Page):
|
|||||||
|
|
||||||
with self.term.loader('Refreshing page'):
|
with self.term.loader('Refreshing page'):
|
||||||
self.content = SubmissionContent.from_url(
|
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:
|
if not self.term.loader.exception:
|
||||||
self.nav = Navigator(self.content.get, page_index=-1)
|
self.nav = Navigator(self.content.get, page_index=-1)
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ history_size = 200
|
|||||||
; Open external links using programs defined in the mailcap config.
|
; Open external links using programs defined in the mailcap config.
|
||||||
enable_media = False
|
enable_media = False
|
||||||
|
|
||||||
|
; Maximum number of columns for a comment
|
||||||
|
max_comment_cols = 120
|
||||||
|
|
||||||
################
|
################
|
||||||
# OAuth Settings
|
# OAuth Settings
|
||||||
################
|
################
|
||||||
|
|||||||
Reference in New Issue
Block a user