]> jfr.im git - irc/quakenet/qwebirc.git/commitdiff
Add nick colouring (resolves issue 44).
authorChris Porter <redacted>
Tue, 23 Jun 2009 01:00:05 +0000 (02:00 +0100)
committerChris Porter <redacted>
Tue, 23 Jun 2009 01:00:05 +0000 (02:00 +0100)
js/irc/baseircclient.js
js/ui/colour.js
js/ui/frontends/qui.js
js/ui/panes/options.js
js/ui/theme.js
js/ui/url.js

index a54d40e0076fc602c209cc9b4e001ac668eddaae..654e5df0b8b0f294f589a1e9a17cc5d7dbc1d627 100644 (file)
@@ -16,8 +16,11 @@ qwebirc.irc.BaseIRCClient = new Class({
   initialize: function(options) {
     this.setOptions(options);
 
+    this.toIRCLower = qwebirc.irc.RFC1459toIRCLower;
+
     this.nickname = this.options.nickname;
-    
+    this.lowerNickname = this.toIRCLower(this.nickname);    
+
     this.__signedOn = false;
     this.pmodes = {b: true, k: true, o: true, l: true, v: true};
     this.channels = {}
@@ -33,7 +36,6 @@ qwebirc.irc.BaseIRCClient = new Class({
     this.connect = this.connection.connect.bind(this.connection);
     this.disconnect = this.connection.disconnect.bind(this.connection);
 
-    this.toIRCLower = qwebirc.irc.RFC1459toIRCLower;
     this.setupGenericErrors();
   },
   dispatch: function(data) {
@@ -83,10 +85,11 @@ qwebirc.irc.BaseIRCClient = new Class({
         /* TODO: warn */
       }
     }
+    this.lowerNickname = this.toIRCLower(this.nickname);
   },
   irc_RPL_WELCOME: function(prefix, params) {
     this.nickname = params[0];
-    
+    this.lowerNickname = this.toIRCLower(this.nickname);
     this.__signedOn = true;
     this.signedOn(this.nickname);
   },
@@ -109,9 +112,11 @@ qwebirc.irc.BaseIRCClient = new Class({
     var oldnick = user.hostToNick();
     var newnick = params[0];
     
-    if(this.nickname == oldnick)
+    if(this.nickname == oldnick) {
       this.nickname = newnick;
-      
+      this.lowerNickname = this.toIRCLower(this.nickname);
+    }
+    
     this.nickChanged(user, newnick);
     
     return true;
index 52ba4046252ad4658b8ba4a86f3bb9cbd5f7b5b2..a5d7c7751e6630e2eb0f7ffaec0b300982d3c819 100644 (file)
@@ -3,7 +3,8 @@ qwebirc.ui.Colourise = function(line, entity, execfn, cmdfn, window) {
   var bg;
   var underline = false;
   var bold = false;
-
+  var autoNickColour = false;
+  
   var out = [];
   var xline = line.split("");
   var element = document.createElement("span");
@@ -43,14 +44,20 @@ qwebirc.ui.Colourise = function(line, entity, execfn, cmdfn, window) {
   }
 
   function emitEndToken() {
+    var data = "";
     if(out.length > 0) {
-      qwebirc.ui.urlificate(element, out.join(""), execfn, cmdfn, window);
+      var data = qwebirc.ui.urlificate(element, out.join(""), execfn, cmdfn, window);
       entity.appendChild(element);
       out = [];
     }
     element = document.createElement("span");
+    return data;
   }  
+  
   function emitStartToken() {
+    if(autoNickColour)
+      return element;
+      
     var classes = []
     if(fg != undefined)
       classes.push("Xc" + fg);
@@ -63,8 +70,37 @@ qwebirc.ui.Colourise = function(line, entity, execfn, cmdfn, window) {
     element.className = classes.join(" ");
   }
   
+  var nickColouring = window.parentObject.uiOptions.NICK_COLOURS; /* HACK */
+  var capturingNick = false;
   for(var i=0;i<xline.length;i++) {
     var lc = xline[i];
+
+    if(nickColouring) {
+      if(!capturingNick) {
+        if(lc == "\x00") {
+          capturingNick = true;
+          emitEndToken();
+          continue;
+        }
+      } else {
+        if(lc != "\x00") {
+          out.push(lc);
+        } else {
+          autoNickColour = true;
+          var e = emitStartToken();
+          var text = emitEndToken();
+          
+          var c = text.toHSBColour(window.client);
+          if($defined(c))
+            e.style.color = c.rgbToHex();
+          capturingNick = autoNickColour = false;
+        }
+        continue;
+      }
+    } else if(lc == "\x00") {
+      continue;
+    }
+    
     if(lc == "\x02") {
       emitEndToken();
 
@@ -101,3 +137,17 @@ qwebirc.ui.Colourise = function(line, entity, execfn, cmdfn, window) {
   
   emitEndToken();
 }
+
+String.prototype.toHSBColour = function(client) {
+  var lower = client.toIRCLower(client.stripPrefix(this));
+  if(lower == client.lowerNickname)
+    return null;
+    
+  var hash = 0;
+  for(var i=0;i<lower.length;i++)
+    hash = 31 * hash + lower.charCodeAt(i);
+  
+  var hue = Math.abs(hash) % 360;
+
+  return new Color([hue, 70, 60], "hsb");
+}
index 9c10dc54248063d72f951d3ad8466adef2834a4f..201b71f773aa10f9f9ee8f83a30f05a781d615d8 100644 (file)
@@ -430,6 +430,8 @@ qwebirc.ui.QUI.Window = new Class({
     } else {
       this.reflow();
     }
+    
+    this.nicksColoured = this.parentObject.uiOptions.NICK_COLOURS;
   },
   editTopic: function() {
     if(!this.client.nickOnChanHasPrefix(this.client.nickname, this.name, "@")) {
@@ -512,13 +514,22 @@ qwebirc.ui.QUI.Window = new Class({
     this.prevNick = null;
   },
   nickListAdd: function(nick, position) {
+    var realNick = this.client.stripPrefix(nick);
+    
     var e = new Element("a");
     qwebirc.ui.insertAt(position, this.nicklist, e);
     
     e.href = "#";
-    e.appendChild(document.createTextNode(nick));
+    var span = new Element("span");
+    if(this.parentObject.uiOptions.NICK_COLOURS) {
+      var colour = realNick.toHSBColour(this.client);
+      if($defined(colour))
+        span.setStyle("color", colour.rgbToHex());
+    }
+    span.set("text", nick);
+    e.appendChild(span);
     
-    e.realNick = this.client.stripPrefix(nick);
+    e.realNick = realNick;
     
     e.addEvent("click", function(x) {
       if(this.prevNick == e) {
@@ -577,6 +588,25 @@ qwebirc.ui.QUI.Window = new Class({
     
     if(inputVisible)
       this.parentObject.inputbox.focus();
+
+    if(this.type == qwebirc.ui.WINDOW_CHANNEL && this.nicksColoured != this.parentObject.uiOptions.NICK_COLOURS) {
+      this.nicksColoured = this.parentObject.uiOptions.NICK_COLOURS;
+      
+      var nodes = this.nicklist.childNodes;
+      if(this.parentObject.uiOptions.NICK_COLOURS) {
+        for(var i=0;i<nodes.length;i++) {
+          var e = nodes[i], span = e.firstChild;
+          var colour = e.realNick.toHSBColour(this.client);
+          if($defined(colour))
+            span.setStyle("color", colour.rgbToHex());
+        };
+      } else {
+        for(var i=0;i<nodes.length;i++) {
+          var span = nodes[i].firstChild;
+          span.setStyle("color", null);
+        };
+      }
+    }
   },
   deselect: function() {
     this.parent();
index a8b7c9352a19700c62624e02abf798fd0e24eabc..ba904871f38639ac2efd0143c502bd67a61ddd98 100644 (file)
@@ -31,7 +31,8 @@ qwebirc.config.DEFAULT_OPTIONS = [
   [3, "NICK_OV_STATUS", "Show status (@/+) before nicknames in nicklist", true],
   [5, "ACCEPT_SERVICE_INVITES", "Automatically join channels when invited by Q", true],
   [6, "USE_HIDDENHOST", "Hide your hostmask when authed to Q (+x)", true],
-  [8, "LASTPOS_LINE", "Show a last position indicator for each window", true]
+  [8, "LASTPOS_LINE", "Show a last position indicator for each window", true],
+  [9, "NICK_COLOURS", "Automatically colour nicknames", false]
 ];
 
 qwebirc.config.DefaultOptions = null;
index bd0b2a8db39804c8384b996fb6b80c2b195c46e8..b8b6db3b2873322159d64bf85a3562a4be323473 100644 (file)
@@ -3,6 +3,8 @@ qwebirc.ui.themes.ThemeControlCodeMap = {
   "B": "\x02",
   "U": "\x1F",
   "O": "\x0F",
+  "{": "\x00",
+  "}": "\x00",
   "[": "qwebirc://whois/",
   "]": "/",
   "$": "$"
@@ -16,31 +18,31 @@ qwebirc.ui.themes.Default = {
   "DISCONNECT": ["Disconnected from server: $m", true],
   "ERROR": ["ERROR: $m", true],
   "SERVERNOTICE": ["$m", true],
-  "JOIN": ["$N [$h] has joined $c", true],
-  "OURJOIN": ["$N [$h] has joined $c", true],
-  "PART": ["$N [$h] has left $c [$m]", true],
-  "KICK": ["$v was kicked from $c by $N [$m]", true],
-  "MODE": ["mode/$c [$m] by $N", true],
-  "QUIT": ["$N [$h] has quit [$m]", true],
-  "NICK": ["$n has changed nick to $[$w$]", true],
-  "TOPIC": ["$N changed the topic of $c to: $m", true],
+  "JOIN": ["${$N$} [$h] has joined $c", true],
+  "OURJOIN": ["${$N$} [$h] has joined $c", true],
+  "PART": ["${$N$} [$h] has left $c [$m]", true],
+  "KICK": ["${$v$} was kicked from $c by ${$N$} [$m]", true],
+  "MODE": ["mode/$c [$m] by ${$N$}", true],
+  "QUIT": ["${$N$} [$h] has quit [$m]", true],
+  "NICK": ["${$n$} has changed nick to ${$[$w$]$}", true],
+  "TOPIC": ["${$N$} changed the topic of $c to: $m", true],
   "UMODE": ["Usermode change: $m", true],
   "INVITE": ["$N invites you to join $c", true],
   "HILIGHT": ["$C4"],
   "HILIGHTEND": ["$O"],
-  "CHANMSG": ["<$@$($N$)> $m"],
+  "CHANMSG": ["<${$@$($N$)$}> $m"],
   "PRIVMSG": ["<$($N$)> $m"],
-  "CHANNOTICE": ["-$($N$):$c- $m"],
+  "CHANNOTICE": ["-${$($N$)$}:$c- $m"],
   "PRIVNOTICE": ["-$($N$)- $m"],
-  "OURCHANMSG": ["<$B$@$N$B> $m"],
-  "OURPRIVMSG": ["<$B$N$B> $m"],
+  "OURCHANMSG": ["<$@$N> $m"],
+  "OURPRIVMSG": ["<$N> $m"],
   "OURTARGETEDMSG": ["*$[$t$]* $m"],
   "OURTARGETEDNOTICE": ["[notice($[$t$])] $m"],
   "OURCHANNOTICE": ["-$N:$t- $m"],
   "OURPRIVNOTICE": ["-$N- $m"],
   "OURCHANACTION": [" * $N $m"],
   "OURPRIVACTION": [" * $N $m"],
-  "CHANACTION": [" * $($N$) $m"],
+  "CHANACTION": [" * ${$($N$)$} $m"],
   "PRIVACTION": [" * $($N$) $m"],
   "CHANCTCP": ["$N [$h] requested CTCP $x from $c: $m"],
   "PRIVCTCP": ["$N [$h] requested CTCP $x from $-: $m"],
@@ -91,11 +93,9 @@ qwebirc.ui.Theme = new Class({
     this.__ccmap = qwebirc.util.dictCopy(qwebirc.ui.themes.ThemeControlCodeMap);
     this.__ccmaph = qwebirc.util.dictCopy(this.__ccmap);
 
-    this.__ccmap["("] = "";
-    this.__ccmap[")"] = "";
-    
     this.__ccmaph["("] = this.message("HILIGHT", {}, this.__ccmap);
     this.__ccmaph[")"] = this.message("HILIGHTEND", {}, this.__ccmap);
+    this.__ccmaph["{"] = this.__ccmaph["}"] = "";
   },
   __dollarSubstitute: function(x, h, mapper) {
     var msg = [];
index 64507eb31e3af90f5eb48ed73f608dc7b880cbe5..d2cb734344096df3fe52ff27b55d4754cd22c769 100644 (file)
@@ -1,6 +1,7 @@
 qwebirc.ui.urlificate = function(element, text, execfn, cmdfn, window) {
   var punct_re = /[[\)|\]]?(\.*|[\,;])$/;
-
+  var addedText = [];
+  
   var txtprocess = function(text, regex, appendfn, matchfn) {
     for(;;) {
       var index = text.search(regex);
@@ -23,11 +24,13 @@ qwebirc.ui.urlificate = function(element, text, execfn, cmdfn, window) {
   };
   
   var appendText = function(text) {
+    addedText.push(text);
     qwebirc.util.NBSPCreate(text, element);
   };
   
   var appendChan = function(text) {
     var newtext = text.replace(punct_re, "");
+    addedText.push(newtext);
     var punct = text.substring(newtext.length);
 
     var a = new Element("span");
@@ -95,6 +98,7 @@ qwebirc.ui.urlificate = function(element, text, execfn, cmdfn, window) {
       if(target)
         a.target = target;
     }
+    addedText.push(disptext);
     a.appendChild(document.createTextNode(disptext));
     
     element.appendChild(a);
@@ -107,4 +111,6 @@ qwebirc.ui.urlificate = function(element, text, execfn, cmdfn, window) {
   txtprocess(text, /\b((https?|ftp|qwebirc):\/\/|www\.)[^ ]+/, function(text) {
     txtprocess(text, /\B#[^ ,]+/, appendText, appendChan);
   }, appendURL);
+  
+  return addedText.join("");
 }