added max column width for comments

This commit is contained in:
Alexandre Kaskasoli
2016-09-28 21:02:54 +01:00
parent 0d5f1f672d
commit b02d867c47
4 changed files with 20 additions and 7 deletions

View File

@@ -67,6 +67,9 @@ def build_parser():
parser.add_argument( parser.add_argument(
'--enable-media', dest='enable_media', action='store_const', const=True, '--enable-media', dest='enable_media', action='store_const', const=True,
help='Open external links using programs defined in the mailcap config') help='Open external links using programs defined in the mailcap config')
parser.add_argument(
'--max-comment-cols', dest='max_comment_cols', type=int,
help='Maximum comment column width')
return parser return parser
@@ -240,8 +243,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)

View File

@@ -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=70):
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=70):
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:

View File

@@ -23,10 +23,13 @@ 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

View File

@@ -57,6 +57,9 @@ oauth_redirect_port = 65000
; Access permissions that will be requested. ; Access permissions that will be requested.
oauth_scope = edit,history,identity,mysubreddits,privatemessages,read,report,save,submit,subscribe,vote oauth_scope = edit,history,identity,mysubreddits,privatemessages,read,report,save,submit,subscribe,vote
; Maximum number of columns for a comment
max_comment_cols = 20
[bindings] [bindings]
############## ##############
# Key Bindings # Key Bindings