mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-26 16:56:37 +00:00
js/{lex,matrix}.js: encode to mIRC more efficiently, pt. II.
This commit is contained in:
parent
e4ed3c9b9e
commit
f9ee0ee4a8
25
js/lex.js
25
js/lex.js
@ -47,22 +47,21 @@ Lex.prototype.sanitize = function(){
|
|||||||
default: return this.char
|
default: return this.char
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var lastBg = -1, lastFg = -1
|
Lex.prototype.mirc = function(bg_, fg_){
|
||||||
Lex.prototype.mirc = function(){
|
|
||||||
var char = this.char || " "
|
var char = this.char || " "
|
||||||
var charIsNaN = isNaN(parseInt(char))
|
var charIsNaN = isNaN(parseInt(char))
|
||||||
if ((lastBg == this.fg) && (lastFg == this.bg)) {
|
if ((bg_ == this.fg) && (fg_ == this.bg)) {
|
||||||
lastBg = this.bg; lastFg = this.fg
|
bg_ = this.bg; fg_ = this.fg
|
||||||
return "\x16" + char
|
return [bg_, fg_, "\x16" + char]
|
||||||
} else if ((lastBg != this.bg) && (lastFg == this.fg)) {
|
} else if ((bg_ != this.bg) && (fg_ == this.fg)) {
|
||||||
lastBg = this.bg
|
bg_ = this.bg
|
||||||
return "\x03," + ((this.bg&15) < 10 && !charIsNaN ? "0" : "") + (this.bg&15) + char
|
return [bg_, fg_, "\x03," + ((this.bg&15) < 10 && !charIsNaN ? "0" : "") + (this.bg&15) + char]
|
||||||
} else if ((lastBg == this.bg) && (lastFg != this.fg)) {
|
} else if ((bg_ == this.bg) && (fg_ != this.fg)) {
|
||||||
lastFg = this.fg
|
fg_ = this.fg
|
||||||
return "\x03" + ((this.fg&15) < 10 && !charIsNaN ? "0" : "") + (this.fg&15) + char
|
return [bg_, fg_, "\x03" + ((this.fg&15) < 10 && !charIsNaN ? "0" : "") + (this.fg&15) + char]
|
||||||
} else {
|
} else {
|
||||||
lastBg = this.bg; lastFg = this.fg
|
bg_ = this.bg; fg_ = this.fg
|
||||||
return "\x03" + (this.fg&15) + "," + ((this.bg&15) < 10 && !charIsNaN ? "0" : "") + (this.bg&15) + char
|
return [bg_, fg_, "\x03" + (this.fg&15) + "," + ((this.bg&15) < 10 && !charIsNaN ? "0" : "") + (this.bg&15) + char]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Lex.prototype.ansi = function(){
|
Lex.prototype.ansi = function(){
|
||||||
|
@ -272,12 +272,13 @@ Matrix.prototype.mirc = function (opts) {
|
|||||||
var lines = this.aa.map(function(row, y){
|
var lines = this.aa.map(function(row, y){
|
||||||
var last, line = ""
|
var last, line = ""
|
||||||
row.forEach(function(lex, x) {
|
row.forEach(function(lex, x) {
|
||||||
|
var bg_ = -1, fg_ = 15
|
||||||
if (lex.eqColor(last)) {
|
if (lex.eqColor(last)) {
|
||||||
line += lex.sanitize()
|
line += lex.sanitize()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
line += lex.mirc()
|
[bg_, fg_, line_] = lex.mirc(bg_, fg_)
|
||||||
last = lex
|
line += line_; last = lex;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (opts && opts.cutoff && line.length > opts.cutoff) {
|
if (opts && opts.cutoff && line.length > opts.cutoff) {
|
||||||
|
Loading…
Reference in New Issue
Block a user