add margin
arg to ParsedLine.truncate so commands/outs.py doesn't do it
manually and cause potential issues with multi-byte chars
This commit is contained in:
parent
d00d026461
commit
938e1db963
2 changed files with 7 additions and 9 deletions
|
@ -44,13 +44,11 @@ class Out(object):
|
||||||
if self._assured:
|
if self._assured:
|
||||||
line.assure()
|
line.assure()
|
||||||
|
|
||||||
valid, truncated = line.truncate(self.server.hostmask())
|
valid, truncated = line.truncate(self.server.hostmask(),
|
||||||
|
margin=STR_MORE_LEN)
|
||||||
|
|
||||||
if truncated:
|
if truncated:
|
||||||
truncated = valid[-STR_MORE_LEN:]+truncated
|
line = utils.irc.parse_line(valid+STR_MORE)
|
||||||
new_line = valid[:-STR_MORE_LEN]+STR_MORE
|
|
||||||
line = utils.irc.parse_line(new_line)
|
|
||||||
|
|
||||||
self._text = "%s%s" % (STR_CONTINUED, truncated)
|
self._text = "%s%s" % (STR_CONTINUED, truncated)
|
||||||
else:
|
else:
|
||||||
self._text = ""
|
self._text = ""
|
||||||
|
|
|
@ -111,13 +111,13 @@ class ParsedLine(object):
|
||||||
else:
|
else:
|
||||||
return line
|
return line
|
||||||
|
|
||||||
def _line_max(self, hostmask: str) -> int:
|
def _line_max(self, hostmask: str, margin: int) -> int:
|
||||||
return LINE_MAX-len((":%s " % hostmask).encode("utf8"))
|
return LINE_MAX-len((":%s " % hostmask).encode("utf8"))-margin
|
||||||
def truncate(self, hostmask: str) -> typing.Tuple[str, str]:
|
def truncate(self, hostmask: str, margin: int=0) -> typing.Tuple[str, str]:
|
||||||
valid_bytes = b""
|
valid_bytes = b""
|
||||||
valid_index = -1
|
valid_index = -1
|
||||||
|
|
||||||
line_max = self._line_max(hostmask)
|
line_max = self._line_max(hostmask, margin)
|
||||||
|
|
||||||
tags_formatted, line_formatted = self._format()
|
tags_formatted, line_formatted = self._format()
|
||||||
for i, char in enumerate(line_formatted):
|
for i, char in enumerate(line_formatted):
|
||||||
|
|
Loading…
Reference in a new issue