js/{lex,matrix}.js: encode to mIRC more efficiently, pt. II.

This commit is contained in:
Lucio Andrés Illanes Albornoz 2018-10-25 00:54:01 +02:00
parent b10c6fb6f7
commit 6be9cbd9b0
2 changed files with 15 additions and 15 deletions

View File

@ -47,22 +47,21 @@ Lex.prototype.sanitize = function(){
default: return this.char
}
}
var lastBg = -1, lastFg = -1
Lex.prototype.mirc = function(){
Lex.prototype.mirc = function(bg_, fg_){
var char = this.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
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
if ((bg_ == this.fg) && (fg_ == this.bg)) {
bg_ = this.bg; fg_ = this.fg
return [bg_, fg_, "\x16" + char]
} else if ((bg_ != this.bg) && (fg_ == this.fg)) {
bg_ = this.bg
return [bg_, fg_, "\x03," + ((this.bg&15) < 10 && !charIsNaN ? "0" : "") + (this.bg&15) + char]
} else if ((bg_ == this.bg) && (fg_ != this.fg)) {
fg_ = this.fg
return [bg_, fg_, "\x03" + ((this.fg&15) < 10 && !charIsNaN ? "0" : "") + (this.fg&15) + char]
} else {
lastBg = this.bg; lastFg = this.fg
return "\x03" + (this.fg&15) + "," + ((this.bg&15) < 10 && !charIsNaN ? "0" : "") + (this.bg&15) + char
bg_ = this.bg; fg_ = this.fg
return [bg_, fg_, "\x03" + (this.fg&15) + "," + ((this.bg&15) < 10 && !charIsNaN ? "0" : "") + (this.bg&15) + char]
}
}
Lex.prototype.ansi = function(){

View File

@ -272,12 +272,13 @@ Matrix.prototype.mirc = function (opts) {
var lines = this.aa.map(function(row, y){
var last, line = ""
row.forEach(function(lex, x) {
var bg_ = -1, fg_ = 15
if (lex.eqColor(last)) {
line += lex.sanitize()
}
else {
line += lex.mirc()
last = lex
[bg_, fg_, line_] = lex.mirc(bg_, fg_)
line += line_; last = lex;
}
})
if (opts && opts.cutoff && line.length > opts.cutoff) {