From 125dbca1d58ecb7b7d7cee45fd74c50a3ee3f26c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz=20=28arab=2C=20vx?= =?UTF-8?q?p=29?= Date: Wed, 24 Oct 2018 18:26:32 +0200 Subject: [PATCH] js/lex.js: encode to mIRC more efficiently. js/lex.js: remove unused fgOnly. --- js/lex.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/js/lex.js b/js/lex.js index b2f54dc..9d170bb 100644 --- a/js/lex.js +++ b/js/lex.js @@ -47,17 +47,24 @@ Lex.prototype.sanitize = function(){ default: return this.char } } -var fgOnly = false +var lastBg = -1, lastFg = -1 Lex.prototype.mirc = function(){ var char = this.char || " " - if (fgOnly) { - return "\x03" + (this.fg&15) + char - } - if ((this.bg&15) < 10 && ! isNaN(parseInt(char))) { - return "\x03" + (this.fg&15) + ",0" + (this.bg&15) + char - } - else { - return "\x03" + (this.fg&15) + "," + (this.bg&15) + char + var charIsNaN = isNaN(parseInt(char)) + if ((lastBg == this.fg) && (lastFg == this.bg)) { + lastBg = this.bg; lastFg = this.fg + return "\x16" + char + } else if ((lastBg != this.bg) && (lastFg != this.fg)) { + lastBg = this.bg; lastFg = this.fg + return "\x03" + (this.fg&15) + "," + ((this.bg&15) < 10 && !charIsNaN ? "0" : "") + (this.bg&15) + char + } else if ((lastBg != this.bg) && (lastFg == this.fg)) { + lastBg = this.bg + return "\x03," + ((this.bg&15) < 10 && !charIsNaN ? "0" : "") + (this.bg&15) + char + } else if ((lastBg == this.bg) && (lastFg != this.fg)) { + lastFg = this.fg + return "\x03" + ((this.fg&15) < 10 && !charIsNaN ? "0" : "") + (this.fg&15) + char + } else { + return "\x03" + "0,1" } } Lex.prototype.ansi = function(){