From a03a89730ae0a3a3d432e95fb57b272a64f26d2e Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sun, 6 Jan 2019 16:48:04 +0100 Subject: [PATCH] Fix bugs in wrapping IRC messages. --- src/callbacks.py | 2 +- src/ircutils.py | 4 ++++ test/test_ircutils.py | 2 -- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/callbacks.py b/src/callbacks.py index c9b6e9d32..7e8b52f30 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -939,7 +939,7 @@ class NestedCommandsIrcProxy(ReplyIrcProxy): return m # The '(XX more messages)' may have not the same # length in the current locale - allowedLength -= len(_('(XX more messages)')) + allowedLength -= len(_('(XX more messages)')) + 1 # bold msgs = ircutils.wrap(s, allowedLength) msgs.reverse() instant = conf.get(conf.supybot.reply.mores.instant,target) diff --git a/src/ircutils.py b/src/ircutils.py index 1512c9a22..010648105 100644 --- a/src/ircutils.py +++ b/src/ircutils.py @@ -540,6 +540,10 @@ class FormatContext(object): IRC string.""" prefix_size = self.bold + self.reverse + self.underline + \ bool(self.fg) + bool(self.bg) + if self.fg and self.bg: + prefix_size += 6 # '\x03xx,yy%s' + elif self.fg or self.bg: + prefix_size += 3 # '\x03xx%s' if prefix_size: return prefix_size + 1 # '\x0f' else: diff --git a/test/test_ircutils.py b/test/test_ircutils.py index ec36ff87f..8d762584c 100644 --- a/test/test_ircutils.py +++ b/test/test_ircutils.py @@ -229,10 +229,8 @@ class FunctionsTestCase(SupyTestCase): s = '\x02\x16 barbazqux' + ('foobarbazqux ' * 20)[0:-1] r = ircutils.wrap(s, 91) - print(list(map(pred, r))) self.assertTrue(max(map(pred, r)) <= 91) - def testSafeArgument(self): s = 'I have been running for 9 seconds' bolds = ircutils.bold(s)