Merge pull request #173 from panicbit/splitpoints

Adjust line splitpoints to word boundaries. closes #159
This commit is contained in:
jesopo 2019-10-12 21:50:24 +01:00 committed by GitHub
commit ea589b744f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,6 +4,7 @@ from src import utils
STR_MORE = " (more...)" STR_MORE = " (more...)"
STR_MORE_LEN = len(STR_MORE.encode("utf8")) STR_MORE_LEN = len(STR_MORE.encode("utf8"))
STR_CONTINUED = "(...continued) " STR_CONTINUED = "(...continued) "
WORD_BOUNDARY = ' '
class Out(object): class Out(object):
def __init__(self, server, module_name, target, target_str, tags): def __init__(self, server, module_name, target, target_str, tags):
@ -54,6 +55,8 @@ class Out(object):
margin=STR_MORE_LEN) margin=STR_MORE_LEN)
if truncated: if truncated:
valid, truncated = self._adjust_to_word_boundaries(valid, truncated)
line = utils.irc.parse_line(valid+STR_MORE) line = utils.irc.parse_line(valid+STR_MORE)
self._text = "%s%s" % (STR_CONTINUED, truncated) self._text = "%s%s" % (STR_CONTINUED, truncated)
else: else:
@ -61,6 +64,17 @@ class Out(object):
sent_line = self.server.send(line) sent_line = self.server.send(line)
def _adjust_to_word_boundaries(self, left, right):
if right[0] == WORD_BOUNDARY:
return left, right
parts = left.rsplit(WORD_BOUNDARY, 1)
if len(parts) != 2:
return left, right
return parts[0], parts[1] + right
def _default_prefix(self, s: str): def _default_prefix(self, s: str):
return s return s
def set_prefix(self, prefix): def set_prefix(self, prefix):