Add ANSI color support.
authorEric S. Raymond <esr@thyrsus.com>
Mon, 1 Oct 2012 22:39:06 +0000 (18:39 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Mon, 1 Oct 2012 22:39:06 +0000 (18:39 -0400)
NEWS
irkerhook.py
irkerhook.xml

diff --git a/NEWS b/NEWS
index 26db304c7dcb7d6c2dc9bf99ebaa5ecea8f677b1..9f68da3adbf49efe6651751154ef216eb1772025 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,7 @@
 1.4 @
   Graceful handling of server disconnects and kicks.
   Distribution now inclues an installable irkerd plist for Mac OS/X.
+  The color variable is no longer boolean; may be miRC or ANSI.
 
 
 
index ebd85d5071a0b2703181e30c4294a15db629b8c2..28671d4205d5930e949ec23333d365d76fce7e4d 100755 (executable)
@@ -49,7 +49,7 @@ def do(command):
 
 class GenericExtractor:
     "Generic class for encapsulating data from a VCS."
-    booleans = ["tcp", "color"]
+    booleans = ["tcp"]
     numerics = ["maxchannels"]
     def __init__(self, arguments):
         self.arguments = arguments
@@ -69,18 +69,26 @@ class GenericExtractor:
         self.files = None
         self.logmsg = None
         self.rev = None
-        self.color = False
+        self.color = None
         # Color highlighting is disabled by default.
         self.bold = self.green = self.blue = ""
         self.yellow = self.brown = self.reset = ""
-    def activate_color(self):
+    def activate_color(self, style):
         "IRC color codes."
-        self.bold = '\x02'
-        self.green = '\x033'
-        self.blue = '\x032'
-        self.yellow = '\x037'
-        self.brown = '\x035'
-        self.reset = '\x0F'
+        if style == 'mIRC':
+            self.bold = '\x02'
+            self.green = '\x033'
+            self.blue = '\x032'
+            self.yellow = '\x037'
+            self.brown = '\x035'
+            self.reset = '\x0F'
+        if style == 'ANSI':
+            self.bold = '\x1b[1m;'
+            self.green = '\x1b[1;2m;'
+            self.blue = '\x1b[1;4m;'
+            self.yellow = '\x1b[1;3m;'
+            self.brown = '\x1b[3m;'
+            self.reset = '\x1b[0m;'
     def load_preferences(self, conf):
         "Load preferences from a file in the repository root."
         if not os.path.exists(conf):
@@ -148,8 +156,8 @@ class GenericExtractor:
                     self.url = webview
             except IOError:
                 self.url = ""
-        if self.color:
-            self.activate_color()
+        if self.color and self.color.lower() != "none":
+            self.activate_color(self.color)
 
 class GitExtractor(GenericExtractor):
     "Metadata extraction for the git version control system."
@@ -162,7 +170,7 @@ class GitExtractor(GenericExtractor):
         self.channels = do("git config --get irker.channels")
         self.tcp = do("git config --bool --get irker.tcp")
         self.template = '%(bold)s%(project)s:%(reset)s %(green)s%(author)s%(reset)s %(repo)s:%(yellow)s%(branch)s%(reset)s * %(bold)s%(rev)s%(reset)s / %(bold)s%(files)s%(reset)s: %(logmsg)s %(brown)s%(url)s%(reset)s'
-        self.color = do("git config --bool --get irker.color")
+        self.color = do("git config --get irker.color")
         self.urlprefix = do("git config --get irker.urlprefix") or "gitweb"
         # This one is git-specific
         self.revformat = do("git config --get irker.revformat")
index 0a0a321f0a243fc436e3555e99817f3d8c0254c4..6229c37472562136eb92bae73d0d449887a9c314 100644 (file)
@@ -117,12 +117,14 @@ will take up less space in the notification line.</para>
 <varlistentry>
 <term>color</term>
 <listitem>
-<para>If "true", highlight notification fields with IRC colors.
-Defaults to "false". Note: if you turn this on and notifications stop
-appearing on your channel, you need to turn off IRC's color filter
-on that channel.  To do this you will need op privileges; issue
-the command "/mode #irker -c".  You may need to first issue
-the command "/msg chanserv set #irker MLOCK +nt-slk".</para>
+<para>If "mIRC", highlight notification fields with mIRC color codes.
+If "ANSI", highlight notification fields with ANSI color escape sequences.
+Defaults to "none" (no colors). Note: if you turn this on and
+notifications stop appearing on your channel, you need to turn off
+IRC's color filter on that channel.  To do this you will need op
+privileges; issue the command "/mode #irker -c".  You may need to
+first issue the command "/msg chanserv set #irker MLOCK
++nt-slk".</para>
 </listitem>
 </varlistentry>
 <varlistentry>