diff --git a/plugins/Filter.py b/plugins/Filter.py index f83a8fa4e..3cf6b4b20 100644 --- a/plugins/Filter.py +++ b/plugins/Filter.py @@ -342,7 +342,7 @@ class Filter(callbacks.Privmsg): """ text = privmsgs.getArgs(args) L = [self._color(c) for c in text] - irc.reply(''.join(L)) + irc.reply('%s%s' % (''.join(L), '\x03')) def colorstrip(self, irc, msg, args): """ diff --git a/src/ircutils.py b/src/ircutils.py index 28c8c9323..c69ec6ff5 100644 --- a/src/ircutils.py +++ b/src/ircutils.py @@ -250,15 +250,15 @@ def joinModes(modes): def bold(s): """Returns the string s, bolded.""" - return '\x02%s\x0F' % s + return '\x02%s\x02' % s def reverse(s): """Returns the string s, reverse-videoed.""" - return '\x16%s\x0F' % s + return '\x16%s\x16' % s def underline(s): """Returns the string s, underlined.""" - return '\x1F%s\x0F' % s + return '\x1F%s\x1F' % s mircColors = { None: '', @@ -292,11 +292,11 @@ def mircColor(s, fg=None, bg=None): if fg is None or isinstance(fg, str): fg = mircColors[fg] if bg is None: - return '\x03%s%s\x0F' % (fg, s) + return '\x03%s%s\x03' % (fg, s) else: if isinstance(bg, str): bg = mircColors[bg] - return '\x03%s,%s%s\x0F' % (fg, bg, s) + return '\x03%s,%s%s\x03' % (fg, bg, s) def canonicalColor(s, bg=False, shift=0): """Assigns an (fg, bg) canonical color pair to a string based on its hash diff --git a/test/test_Filter.py b/test/test_Filter.py index dd30bf68f..7cd69c838 100644 --- a/test/test_Filter.py +++ b/test/test_Filter.py @@ -80,6 +80,8 @@ class FilterTest(ChannelPluginTestCase, PluginDocumentation): def testColorize(self): self.assertNotRegexp('colorize foobar', r'\s+') self.assertRegexp('colorize foobar', r'\x03') + # Make sure we're closing colorize with an 'end color' marker + self.assertRegexp('colorize foobar', r'\x03$') _strings = ('Supybot pwns!', '123456', 'A string with \x02bold\x15') def testColorstrip(self): diff --git a/test/test_ircutils.py b/test/test_ircutils.py index 85dcd6f37..c44e72ba6 100644 --- a/test/test_ircutils.py +++ b/test/test_ircutils.py @@ -91,20 +91,20 @@ class FunctionsTestCase(SupyTestCase): def testBold(self): s = ircutils.bold('foo') self.assertEqual(s[0], '\x02') - self.assertEqual(s[-1], '\x0F') + self.assertEqual(s[-1], '\x02') def testMircColor(self): # No colors provided should return the same string s = 'foo' self.assertEqual(s, ircutils.mircColor(s)) # Test positional args - self.assertEqual('\x030foo\x0F', ircutils.mircColor(s, 'white')) - self.assertEqual('\x031,2foo\x0F',ircutils.mircColor(s,'black','blue')) - self.assertEqual('\x03,3foo\x0F', ircutils.mircColor(s, None, 'green')) + self.assertEqual('\x030foo\x03', ircutils.mircColor(s, 'white')) + self.assertEqual('\x031,2foo\x03',ircutils.mircColor(s,'black','blue')) + self.assertEqual('\x03,3foo\x03', ircutils.mircColor(s, None, 'green')) # Test keyword args - self.assertEqual('\x034foo\x0F', ircutils.mircColor(s, fg='red')) - self.assertEqual('\x03,5foo\x0F', ircutils.mircColor(s, bg='brown')) - self.assertEqual('\x036,7foo\x0F', + self.assertEqual('\x034foo\x03', ircutils.mircColor(s, fg='red')) + self.assertEqual('\x03,5foo\x03', ircutils.mircColor(s, bg='brown')) + self.assertEqual('\x036,7foo\x03', ircutils.mircColor(s, bg='orange', fg='purple')) def testMircColors(self): @@ -179,20 +179,15 @@ class FunctionsTestCase(SupyTestCase): self.assertEqual(ircutils.unColor('\x02bold\x0302,04foo\x03bar\x0f'), '\x02boldfoobar\x0f') self.assertEqual(ircutils.unColor('\x03foo\x03'), 'foo') - self.assertEqual(ircutils.unColor('\x03foo\x0F'), 'foo') + self.assertEqual(ircutils.unColor('\x03foo\x0F'), 'foo\x0F') self.assertEqual(ircutils.unColor('\x0312foo\x03'), 'foo') self.assertEqual(ircutils.unColor('\x0312,14foo\x03'), 'foo') self.assertEqual(ircutils.unColor('\x03,14foo\x03'), 'foo') self.assertEqual(ircutils.unColor('\x03,foo\x03'), ',foo') - # These tests aren't going to pass until I decide how to handle - # stripping of \x0f. We don't want to just rampantly remove \x0f - # because it may be a clear code from some other formatting. Leaving - # it in doesn't adversely affect anything, so for now I'm not removing - # it. - self.assertEqual(ircutils.unColor('\x0312foo\x0F'), 'foo') - self.assertEqual(ircutils.unColor('\x0312,14foo\x0F'), 'foo') - self.assertEqual(ircutils.unColor('\x03,14foo\x0F'), 'foo') - self.assertEqual(ircutils.unColor('\x03,foo\x0F'), ',foo') + self.assertEqual(ircutils.unColor('\x0312foo\x0F'), 'foo\x0F') + self.assertEqual(ircutils.unColor('\x0312,14foo\x0F'), 'foo\x0F') + self.assertEqual(ircutils.unColor('\x03,14foo\x0F'), 'foo\x0F') + self.assertEqual(ircutils.unColor('\x03,foo\x0F'), ',foo\x0F') def testDccIpStuff(self): def randomIP():