function Lex (x,y) { if (typeof x == "number") { this.y = y this.x = x this.span = document.createElement("span") } else { this.span = x } this.fg = colors.white this.bg = colors.black this.char = " " } Lex.prototype.build = function(){ this.span.className = this.css() this.span.innerHTML = this.html() } Lex.prototype.css = function(){ return "f" + letters[mod(this.fg,16)] + "b" + letters[mod(this.bg,16)] } Lex.prototype.html = function(){ return this.char == " " ? " " : this.char || " " } Lex.prototype.read = function(){ this.char = this.span.innerHTML return this.char } Lex.prototype.ascii = function(){ return this.char || " " } Lex.prototype.sanitize = function(){ return this.char == "%" ? '%%' : this.char || " " } var fgOnly = false Lex.prototype.mirc = function(){ var char = this.char || " " if (parseInt(char)) { char = "\x02\x02" + char } if (fgOnly) { return "\x03" + (this.fg&15) + char } if (this.bg == 1 && this.fg == 0) { return char } else { return "\x03" + (this.fg&15) + "," + (this.bg&15) + char } } Lex.prototype.clone = function (lex){ if (lex.opacity == 0) return this.fg = lex.fg this.bg = lex.bg this.char = lex.char this.build() } Lex.prototype.erase = function (lex){ if (lex.opacity == 0) return this.fg = colors.white this.bg = colors.black this.char = " " this.build() } Lex.prototype.fill = function(fg,bg){ this.fg = fg this.bg = bg this.opacity = 1 this.build() } Lex.prototype.eq = function(lex){ return lex && this.fg == lex.fg && this.bg == lex.fg && this.char == lex.char } Lex.prototype.clear = function(){ this.bg = 1 this.fg = 0 this.char = " " this.opacity = 0 this.build() } Lex.prototype.isClear = function(){ return this.bg == 1 && this.fg == 0 && this.char == " " } Lex.prototype.focus = function(){ if (focused) focused.blur() this.span.classList.add('focused') focused = this } Lex.prototype.blur = function(){ this.span.classList.remove('focused') focused = null } Lex.prototype.demolish = function(){ this.span.parentNode.removeChild(this.span) this.span = null } Lex.prototype.key = function(char, keyCode) { if (! char) { return } this.char = char this.fg = brush.bg this.build() }