143 lines
4.3 KiB
JavaScript
143 lines
4.3 KiB
JavaScript
// Generated by CoffeeScript 1.7.1
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
this.ImageTextModeAVATAR = (function(_super) {
|
|
__extends(ImageTextModeAVATAR, _super);
|
|
|
|
function ImageTextModeAVATAR(options) {
|
|
var k, v;
|
|
ImageTextModeAVATAR.__super__.constructor.apply(this, arguments);
|
|
this.tabstop = 8;
|
|
this.linewrap = 80;
|
|
for (k in options) {
|
|
if (!__hasProp.call(options, k)) continue;
|
|
v = options[k];
|
|
this[k] = v;
|
|
}
|
|
}
|
|
|
|
ImageTextModeAVATAR.prototype.parse = function(content) {
|
|
var c, ch, i, _results;
|
|
this.screen = [];
|
|
this.x = 0;
|
|
this.y = 0;
|
|
this.attr = 3;
|
|
content = content.split('');
|
|
_results = [];
|
|
while (ch = content.shift()) {
|
|
if (ch === "\x1a") {
|
|
break;
|
|
} else if (ch === "\n") {
|
|
this.x = 0;
|
|
_results.push(this.y++);
|
|
} else if (ch === "\r") {
|
|
continue;
|
|
} else if (ch === "\t") {
|
|
i = (this.x + 1) % this.tabstop;
|
|
_results.push((function() {
|
|
var _results1;
|
|
_results1 = [];
|
|
while (i-- > 0) {
|
|
_results1.push(this.putpixel(' '));
|
|
}
|
|
return _results1;
|
|
}).call(this));
|
|
} else if (ch.charCodeAt(0) === 12) {
|
|
this.screen = [];
|
|
this.attr = 3;
|
|
_results.push(this.insert = false);
|
|
} else if (ch.charCodeAt(0) === 25) {
|
|
ch = content.shift();
|
|
i = content.shift().charCodeAt(0);
|
|
_results.push((function() {
|
|
var _results1;
|
|
_results1 = [];
|
|
while (i-- > 0) {
|
|
_results1.push(this.putpixel(ch));
|
|
}
|
|
return _results1;
|
|
}).call(this));
|
|
} else if (ch.charCodeAt(0) === 22) {
|
|
c = content.shift().charCodeAt(0);
|
|
switch (c) {
|
|
case 1:
|
|
_results.push(this.attr = content.shift().charCodeAt(0) & 0x7f);
|
|
break;
|
|
case 2:
|
|
_results.push(this.attr |= 0x80);
|
|
break;
|
|
case 3:
|
|
this.y--;
|
|
if (this.y < 0) {
|
|
_results.push(this.y = 0);
|
|
} else {
|
|
_results.push(void 0);
|
|
}
|
|
break;
|
|
case 4:
|
|
_results.push(this.y++);
|
|
break;
|
|
case 5:
|
|
this.x--;
|
|
if (this.x < 0) {
|
|
_results.push(this.x = 0);
|
|
} else {
|
|
_results.push(void 0);
|
|
}
|
|
break;
|
|
case 6:
|
|
_results.push(this.x++);
|
|
break;
|
|
case 7:
|
|
_results.push((function() {
|
|
var _i, _ref, _ref1, _results1;
|
|
_results1 = [];
|
|
for (i = _i = _ref = this.x, _ref1 = screen[this.y].length - 1; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; i = _ref <= _ref1 ? ++_i : --_i) {
|
|
_results1.push(this.screen[this.y][i] = null);
|
|
}
|
|
return _results1;
|
|
}).call(this));
|
|
break;
|
|
case 8:
|
|
this.y = content.shift().charCodeAt(0) - 1;
|
|
this.x = content.shift().charCodeAt(0) - 1;
|
|
if (this.y < 0) {
|
|
this.y = 0;
|
|
}
|
|
if (this.x < 0) {
|
|
_results.push(this.x = 0);
|
|
} else {
|
|
_results.push(void 0);
|
|
}
|
|
break;
|
|
default:
|
|
_results.push(void 0);
|
|
}
|
|
} else {
|
|
_results.push(this.putpixel(ch));
|
|
}
|
|
}
|
|
return _results;
|
|
};
|
|
|
|
ImageTextModeAVATAR.prototype.putpixel = function(ch) {
|
|
if (this.screen[this.y] == null) {
|
|
this.screen[this.y] = [];
|
|
}
|
|
this.screen[this.y][this.x] = {
|
|
ch: ch,
|
|
attr: this.attr
|
|
};
|
|
if (++this.x >= this.linewrap) {
|
|
this.x = 0;
|
|
return this.y++;
|
|
}
|
|
};
|
|
|
|
return ImageTextModeAVATAR;
|
|
|
|
})(this.ImageTextMode);
|
|
|
|
}).call(this);
|