paradoxxxzero_butterfly/butterfly/static/javascripts/worker.js

1712 lines
44 KiB
JavaScript

// Generated by CoffeeScript 1.6.3
var BackTerminal, State, backterm, s, ws;
ws = null;
backterm = null;
self.addEventListener('message', function(e) {
switch (e.data.cmd) {
case 'init':
backterm = new BackTerminal(e.data.cols, e.data.rows);
ws = new WebSocket(e.data.wsurl);
ws.addEventListener('open', function() {
console.log("WebSocket open", arguments);
return ws.send('R' + e.data.cols + ',' + e.data.rows);
});
ws.addEventListener('error', function() {
return console.log("WebSocket error", arguments);
});
ws.addEventListener('message', function(e) {
return backterm.write(e.data);
});
return ws.addEventListener('close', function() {
return console.log("WebSocket closed", arguments);
});
case 'data':
return ws.send('S' + e.data.data);
}
});
s = 0;
State = {
normal: s++,
escaped: s++,
csi: s++,
osc: s++,
charset: s++,
dcs: s++,
ignore: s++
};
BackTerminal = (function() {
function BackTerminal(cols, rows) {
this.cols = cols;
this.rows = rows;
this.scrollback = 100000;
this.visualBell = 100;
this.convertEol = false;
this.termName = 'xterm';
this.cursorBlink = true;
this.screenKeys = false;
this.cursorState = 0;
this.reset_vars();
}
BackTerminal.prototype.reset_vars = function() {
var i;
this.ybase = 0;
this.ydisp = 0;
this.x = 0;
this.y = 0;
this.state = State.normal;
this.scrollTop = 0;
this.scrollBottom = this.rows - 1;
this.applicationKeypad = false;
this.applicationCursor = false;
this.originMode = false;
this.wraparoundMode = false;
this.normal = null;
this.charset = null;
this.gcharset = null;
this.glevel = 0;
this.charsets = [null];
this.defAttr = (0 << 18) | (257 << 9) | (256 << 0);
this.curAttr = this.defAttr;
this.params = [];
this.currentParam = 0;
this.prefix = "";
this.lines = [];
i = this.rows;
while (i--) {
this.lines.push(this.blankLine());
}
return this.setupStops();
};
BackTerminal.prototype.eraseAttr = function() {
return (this.defAttr & ~0x1ff) | (this.curAttr & 0x1ff);
};
BackTerminal.prototype.scroll = function() {
var row;
if (++this.ybase === this.scrollback) {
this.ybase = this.ybase / 2 | 0;
this.lines = this.lines.slice(-(this.ybase + this.rows) + 1);
}
this.ydisp = this.ybase;
row = this.ybase + this.rows - 1;
row -= this.rows - 1 - this.scrollBottom;
if (row === this.lines.length) {
this.lines.push(this.blankLine());
} else {
this.lines.splice(row, 0, this.blankLine());
}
if (this.scrollTop !== 0) {
if (this.ybase !== 0) {
this.ybase--;
this.ydisp = this.ybase;
}
this.lines.splice(this.ybase + this.scrollTop, 1);
}
this.updateRange(this.scrollTop);
return this.updateRange(this.scrollBottom);
};
BackTerminal.prototype.scrollDisp = function(disp) {
this.ydisp += disp;
if (this.ydisp > this.ybase) {
this.ydisp = this.ybase;
} else {
if (this.ydisp < 0) {
this.ydisp = 0;
}
}
return this.refresh(0, this.rows - 1);
};
BackTerminal.prototype.refresh = function(start, end) {
return self.postMessage({
cmd: 'refresh',
lines: this.lines.slice(this.ydisp, this.ydisp + this.rows),
start: start,
end: end
});
};
BackTerminal.prototype.write = function(data) {
var ch, cs, html, i, j, l, line, pt, valid, _ref;
this.refreshStart = this.y;
this.refreshEnd = this.y;
if (this.ybase !== this.ydisp) {
this.ydisp = this.ybase;
this.maxRange();
}
i = 0;
l = data.length;
while (i < l) {
ch = data[i];
switch (this.state) {
case State.normal:
switch (ch) {
case "\x07":
this.bell();
break;
case "\n":
case "\x0b":
case "\x0c":
if (this.convertEol) {
this.x = 0;
}
this.y++;
if (this.y > this.scrollBottom) {
this.y--;
this.scroll();
}
break;
case "\r":
this.x = 0;
break;
case "\b":
if (this.x > 0) {
this.x--;
}
break;
case "\t":
this.x = this.nextStop();
break;
case "\x0e":
this.setgLevel(1);
break;
case "\x0f":
this.setgLevel(0);
break;
case "\x1b":
this.state = State.escaped;
break;
default:
if (ch >= " ") {
if ((_ref = this.charset) != null ? _ref[ch] : void 0) {
ch = this.charset[ch];
}
if (this.x >= this.cols) {
this.x = 0;
this.y++;
if (this.y > this.scrollBottom) {
this.y--;
this.scroll();
}
}
this.lines[this.y + this.ybase][this.x] = [this.curAttr, ch];
this.x++;
this.updateRange(this.y);
if (("\uff00" < ch && ch < "\uffef")) {
j = this.y + this.ybase;
if (this.cols < 2 || this.x >= this.cols) {
this.lines[j][this.x - 1] = [this.curAttr, " "];
break;
}
this.lines[j][this.x] = [this.curAttr, " "];
this.x++;
}
}
}
break;
case State.escaped:
switch (ch) {
case "[":
this.params = [];
this.currentParam = 0;
this.state = State.csi;
break;
case "]":
this.params = [];
this.currentParam = 0;
this.state = State.osc;
break;
case "P":
this.params = [];
this.currentParam = 0;
this.state = State.dcs;
break;
case "_":
this.state = State.ignore;
break;
case "^":
this.state = State.ignore;
break;
case "c":
this.reset();
break;
case "E":
this.x = 0;
this.index();
break;
case "D":
this.index();
break;
case "M":
this.reverseIndex();
break;
case "%":
this.setgLevel(0);
this.setgCharset(0, BackTerminal.prototype.charsets.US);
this.state = State.normal;
i++;
break;
case "(":
case ")":
case "*":
case "+":
case "-":
case ".":
switch (ch) {
case "(":
this.gcharset = 0;
break;
case ")":
case "-":
this.gcharset = 1;
break;
case "*":
case ".":
this.gcharset = 2;
break;
case "+":
this.gcharset = 3;
}
this.state = State.charset;
break;
case "/":
this.gcharset = 3;
this.state = State.charset;
i--;
break;
case "n":
this.setgLevel(2);
break;
case "o":
this.setgLevel(3);
break;
case "|":
this.setgLevel(3);
break;
case "}":
this.setgLevel(2);
break;
case "~":
this.setgLevel(1);
break;
case "7":
this.saveCursor();
this.state = State.normal;
break;
case "8":
this.restoreCursor();
this.state = State.normal;
break;
case "#":
this.state = State.normal;
i++;
break;
case "H":
this.tabSet();
break;
case "=":
this.applicationKeypad = true;
this.state = State.normal;
break;
case ">":
this.applicationKeypad = false;
this.state = State.normal;
break;
default:
this.state = State.normal;
console.log("Unknown ESC control:", ch);
}
break;
case State.charset:
switch (ch) {
case "0":
cs = BackTerminal.prototype.charsets.SCLD;
break;
case "A":
cs = BackTerminal.prototype.charsets.UK;
break;
case "B":
cs = BackTerminal.prototype.charsets.US;
break;
case "4":
cs = BackTerminal.prototype.charsets.Dutch;
break;
case "C":
case "5":
cs = BackTerminal.prototype.charsets.Finnish;
break;
case "R":
cs = BackTerminal.prototype.charsets.French;
break;
case "Q":
cs = BackTerminal.prototype.charsets.FrenchCanadian;
break;
case "K":
cs = BackTerminal.prototype.charsets.German;
break;
case "Y":
cs = BackTerminal.prototype.charsets.Italian;
break;
case "E":
case "6":
cs = BackTerminal.prototype.charsets.NorwegianDanish;
break;
case "Z":
cs = BackTerminal.prototype.charsets.Spanish;
break;
case "H":
case "7":
cs = BackTerminal.prototype.charsets.Swedish;
break;
case "=":
cs = BackTerminal.prototype.charsets.Swiss;
break;
case "/":
cs = BackTerminal.prototype.charsets.ISOLatin;
i++;
break;
default:
cs = BackTerminal.prototype.charsets.US;
}
this.setgCharset(this.gcharset, cs);
this.gcharset = null;
this.state = State.normal;
break;
case State.osc:
if (ch === "\x1b" || ch === "\x07") {
if (ch === "\x1b") {
i++;
}
this.params.push(this.currentParam);
switch (this.params[0]) {
case 0:
case 1:
case 2:
if (this.params[1]) {
this.title = this.params[1] + " - ƸӜƷ butterfly";
this.handleTitle(this.title);
}
break;
case 99:
html = "<div class=\"inline-html\">" + this.params[1] + "</div>";
this.lines[this.y + this.ybase][this.x] = [this.curAttr, html];
line = 0;
while (line < this.get_html_height_in_lines(html) - 1) {
this.y++;
if (this.y > this.scrollBottom) {
this.y--;
this.scroll();
}
line++;
}
this.updateRange(this.y);
}
this.params = [];
this.currentParam = 0;
this.state = State.normal;
} else {
if (!this.params.length) {
if (ch >= "0" && ch <= "9") {
this.currentParam = this.currentParam * 10 + ch.charCodeAt(0) - 48;
} else if (ch === ";") {
this.params.push(this.currentParam);
this.currentParam = "";
}
} else {
this.currentParam += ch;
}
}
break;
case State.csi:
if (ch === "?" || ch === ">" || ch === "!") {
this.prefix = ch;
break;
}
if (ch >= "0" && ch <= "9") {
this.currentParam = this.currentParam * 10 + ch.charCodeAt(0) - 48;
break;
}
if (ch === "$" || ch === "\"" || ch === " " || ch === "'") {
break;
}
this.params.push(this.currentParam);
this.currentParam = 0;
if (ch === ";") {
break;
}
this.state = State.normal;
switch (ch) {
case "A":
this.cursorUp(this.params);
break;
case "B":
this.cursorDown(this.params);
break;
case "C":
this.cursorForward(this.params);
break;
case "D":
this.cursorBackward(this.params);
break;
case "H":
this.cursorPos(this.params);
break;
case "J":
this.eraseInDisplay(this.params);
break;
case "K":
this.eraseInLine(this.params);
break;
case "m":
if (!this.prefix) {
this.charAttributes(this.params);
}
break;
case "n":
if (!this.prefix) {
this.deviceStatus(this.params);
}
break;
case "@":
this.insertChars(this.params);
break;
case "E":
this.cursorNextLine(this.params);
break;
case "F":
this.cursorPrecedingLine(this.params);
break;
case "G":
this.cursorCharAbsolute(this.params);
break;
case "L":
this.insertLines(this.params);
break;
case "M":
this.deleteLines(this.params);
break;
case "P":
this.deleteChars(this.params);
break;
case "X":
this.eraseChars(this.params);
break;
case "`":
this.charPosAbsolute(this.params);
break;
case "a":
this.HPositionRelative(this.params);
break;
case "c":
this.sendDeviceAttributes(this.params);
break;
case "d":
this.linePosAbsolute(this.params);
break;
case "e":
this.VPositionRelative(this.params);
break;
case "f":
this.HVPosition(this.params);
break;
case "h":
this.setMode(this.params);
break;
case "l":
this.resetMode(this.params);
break;
case "r":
this.setScrollRegion(this.params);
break;
case "s":
this.saveCursor(this.params);
break;
case "u":
this.restoreCursor(this.params);
break;
case "I":
this.cursorForwardTab(this.params);
break;
case "S":
this.scrollUp(this.params);
break;
case "T":
if (this.params.length < 2 && !this.prefix) {
this.scrollDown(this.params);
}
break;
case "Z":
this.cursorBackwardTab(this.params);
break;
case "b":
this.repeatPrecedingCharacter(this.params);
break;
case "g":
this.tabClear(this.params);
break;
case "p":
if (this.prefix === '!') {
this.softReset(this.params);
}
break;
default:
this.error("Unknown CSI code: %s.", ch);
}
this.prefix = "";
break;
case State.dcs:
if (ch === "\x1b" || ch === "\x07") {
if (ch === "\x1b") {
i++;
}
switch (this.prefix) {
case "":
break;
case "$q":
pt = this.currentParam;
valid = false;
switch (pt) {
case "\"q":
pt = "0\"q";
break;
case "\"p":
pt = "61\"p";
break;
case "r":
pt = "" + (this.scrollTop + 1) + ";" + (this.scrollBottom + 1) + "r";
break;
case "m":
pt = "0m";
break;
default:
this.error("Unknown DCS Pt: %s.", pt);
pt = "";
}
this.send("\x1bP" + +valid + "$r" + pt + "\x1b\\");
break;
case "+q":
pt = this.currentParam;
valid = false;
this.send("\x1bP" + +valid + "+r" + pt + "\x1b\\");
break;
default:
this.error("Unknown DCS prefix: %s.", this.prefix);
}
this.currentParam = 0;
this.prefix = "";
this.state = State.normal;
} else if (!this.currentParam) {
if (!this.prefix && ch !== "$" && ch !== "+") {
this.currentParam = ch;
} else if (this.prefix.length === 2) {
this.currentParam = ch;
} else {
this.prefix += ch;
}
} else {
this.currentParam += ch;
}
break;
case State.ignore:
if (ch === "\x1b" || ch === "\x07") {
if (ch === "\x1b") {
i++;
}
this.state = State.normal;
}
}
i++;
}
this.updateRange(this.y);
return this.refresh(this.refreshStart, this.refreshEnd);
};
BackTerminal.prototype.writeln = function(data) {
return this.write("" + data + "\r\n");
};
BackTerminal.prototype.setgLevel = function(g) {
this.glevel = g;
return this.charset = this.charsets[g];
};
BackTerminal.prototype.setgCharset = function(g, charset) {
this.charsets[g] = charset;
if (this.glevel === g) {
return this.charset = charset;
}
};
BackTerminal.prototype.resize = function(cols, rows) {
var ch, i, j;
this.cols = cols;
this.rows = rows;
if (old_cols < this.cols) {
ch = [this.defAttr, " "];
i = this.lines.length;
while (i--) {
while (this.lines[i].length < this.cols) {
this.lines[i].push(ch);
}
}
} else if (old_cols > this.cols) {
i = this.lines.length;
while (i--) {
while (this.lines[i].length > this.cols) {
this.lines[i].pop();
}
}
}
this.setupStops(old_cols);
j = old_rows;
if (j < this.rows) {
while (j++ < this.rows) {
if (this.lines.length < this.rows + this.ybase) {
this.lines.push(this.blankLine());
}
}
} else if (j > this.rows) {
while (j-- > this.rows) {
if (this.lines.length > this.rows + this.ybase) {
this.lines.pop();
}
}
}
if (this.y >= this.rows) {
this.y = this.rows - 1;
}
if (this.x >= this.cols) {
this.x = this.cols - 1;
}
this.scrollTop = 0;
this.scrollBottom = this.rows - 1;
return this.normal = null;
};
BackTerminal.prototype.updateRange = function(y) {
if (y < this.refreshStart) {
this.refreshStart = y;
}
if (y > this.refreshEnd) {
return this.refreshEnd = y;
}
};
BackTerminal.prototype.maxRange = function() {
this.refreshStart = 0;
return this.refreshEnd = this.rows - 1;
};
BackTerminal.prototype.setupStops = function(i) {
var _results;
if (i != null) {
if (!this.tabs[i]) {
i = this.prevStop(i);
}
} else {
this.tabs = {};
i = 0;
}
_results = [];
while (i < this.cols) {
this.tabs[i] = true;
_results.push(i += 8);
}
return _results;
};
BackTerminal.prototype.prevStop = function(x) {
if (x == null) {
x = this.x;
}
while (!this.tabs[--x] && x > 0) {
1;
}
if (x >= this.cols) {
return this.cols - 1;
} else {
if (x < 0) {
return 0;
} else {
return x;
}
}
};
BackTerminal.prototype.nextStop = function(x) {
if (x == null) {
x = this.x;
}
while (!this.tabs[++x] && x < this.cols) {
1;
}
if (x >= this.cols) {
return this.cols - 1;
} else {
if (x < 0) {
return 0;
} else {
return x;
}
}
};
BackTerminal.prototype.eraseRight = function(x, y) {
var ch, line;
line = this.lines[this.ybase + y];
ch = [this.eraseAttr(), " "];
while (x < this.cols) {
line[x] = ch;
x++;
}
return this.updateRange(y);
};
BackTerminal.prototype.eraseLeft = function(x, y) {
var ch, line;
line = this.lines[this.ybase + y];
ch = [this.eraseAttr(), " "];
x++;
while (x--) {
line[x] = ch;
}
return this.updateRange(y);
};
BackTerminal.prototype.eraseLine = function(y) {
return this.eraseRight(0, y);
};
BackTerminal.prototype.blankLine = function(cur) {
var attr, ch, i, line;
attr = (cur ? this.eraseAttr() : this.defAttr);
ch = [attr, " "];
line = [];
i = 0;
while (i < this.cols) {
line[i] = ch;
i++;
}
return line;
};
BackTerminal.prototype.ch = function(cur) {
if (cur) {
return [this.eraseAttr(), " "];
} else {
return [this.defAttr, " "];
}
};
BackTerminal.prototype.isterm = function(term) {
return ("" + this.termName).indexOf(term) === 0;
};
BackTerminal.prototype.handler = function(data) {
return this.out(data);
};
BackTerminal.prototype.handleTitle = function(title) {};
BackTerminal.prototype.index = function() {
this.y++;
if (this.y > this.scrollBottom) {
this.y--;
this.scroll();
}
return this.state = State.normal;
};
BackTerminal.prototype.reverseIndex = function() {
var j;
this.y--;
if (this.y < this.scrollTop) {
this.y++;
this.lines.splice(this.y + this.ybase, 0, this.blankLine(true));
j = this.rows - 1 - this.scrollBottom;
this.lines.splice(this.rows - 1 + this.ybase - j + 1, 1);
this.updateRange(this.scrollTop);
this.updateRange(this.scrollBottom);
}
return this.state = State.normal;
};
BackTerminal.prototype.reset = function() {
this.reset_vars();
return this.refresh(0, this.rows - 1);
};
BackTerminal.prototype.tabSet = function() {
this.tabs[this.x] = true;
return this.state = State.normal;
};
BackTerminal.prototype.cursorUp = function(params) {
var param;
param = params[0];
if (param < 1) {
param = 1;
}
this.y -= param;
if (this.y < 0) {
return this.y = 0;
}
};
BackTerminal.prototype.cursorDown = function(params) {
var param;
param = params[0];
if (param < 1) {
param = 1;
}
this.y += param;
if (this.y >= this.rows) {
return this.y = this.rows - 1;
}
};
BackTerminal.prototype.cursorForward = function(params) {
var param;
param = params[0];
if (param < 1) {
param = 1;
}
this.x += param;
if (this.x >= this.cols) {
return this.x = this.cols - 1;
}
};
BackTerminal.prototype.cursorBackward = function(params) {
var param;
param = params[0];
if (param < 1) {
param = 1;
}
this.x -= param;
if (this.x < 0) {
return this.x = 0;
}
};
BackTerminal.prototype.cursorPos = function(params) {
var col, row;
row = params[0] - 1;
if (params.length >= 2) {
col = params[1] - 1;
} else {
col = 0;
}
if (row < 0) {
row = 0;
} else {
if (row >= this.rows) {
row = this.rows - 1;
}
}
if (col < 0) {
col = 0;
} else {
if (col >= this.cols) {
col = this.cols - 1;
}
}
this.x = col;
return this.y = row;
};
BackTerminal.prototype.eraseInDisplay = function(params) {
var j, _results, _results1, _results2;
switch (params[0]) {
case 0:
this.eraseRight(this.x, this.y);
j = this.y + 1;
_results = [];
while (j < this.rows) {
this.eraseLine(j);
_results.push(j++);
}
return _results;
break;
case 1:
this.eraseLeft(this.x, this.y);
j = this.y;
_results1 = [];
while (j--) {
_results1.push(this.eraseLine(j));
}
return _results1;
break;
case 2:
j = this.rows;
_results2 = [];
while (j--) {
_results2.push(this.eraseLine(j));
}
return _results2;
}
};
BackTerminal.prototype.eraseInLine = function(params) {
switch (params[0]) {
case 0:
return this.eraseRight(this.x, this.y);
case 1:
return this.eraseLeft(this.x, this.y);
case 2:
return this.eraseLine(this.y);
}
};
BackTerminal.prototype.charAttributes = function(params) {
var bg, fg, flags, i, l, p;
if (params.length === 1 && params[0] === 0) {
this.curAttr = this.defAttr;
return;
}
flags = this.curAttr >> 18;
fg = (this.curAttr >> 9) & 0x1ff;
bg = this.curAttr & 0x1ff;
l = params.length;
i = 0;
while (i < l) {
p = params[i];
if (p >= 30 && p <= 37) {
fg = p - 30;
} else if (p >= 40 && p <= 47) {
bg = p - 40;
} else if (p >= 90 && p <= 97) {
p += 8;
fg = p - 90;
} else if (p >= 100 && p <= 107) {
p += 8;
bg = p - 100;
} else if (p === 0) {
flags = this.defAttr >> 18;
fg = (this.defAttr >> 9) & 0x1ff;
bg = this.defAttr & 0x1ff;
} else if (p === 1) {
flags |= 1;
} else if (p === 4) {
flags |= 2;
} else if (p === 5) {
flags |= 4;
} else if (p === 7) {
flags |= 8;
} else if (p === 8) {
flags |= 16;
} else if (p === 22) {
flags &= ~1;
} else if (p === 24) {
flags &= ~2;
} else if (p === 25) {
flags &= ~4;
} else if (p === 27) {
flags &= ~8;
} else if (p === 28) {
flags &= ~16;
} else if (p === 39) {
fg = (this.defAttr >> 9) & 0x1ff;
} else if (p === 49) {
bg = this.defAttr & 0x1ff;
} else if (p === 38) {
if (params[i + 1] === 2) {
i += 2;
fg = "#" + params[i] & 0xff + params[i + 1] & 0xff + params[i + 2] & 0xff;
i += 2;
} else if (params[i + 1] === 5) {
i += 2;
fg = params[i] & 0xff;
}
} else if (p === 48) {
if (params[i + 1] === 2) {
i += 2;
bg = "#" + params[i] & 0xff + params[i + 1] & 0xff + params[i + 2] & 0xff;
i += 2;
} else if (params[i + 1] === 5) {
i += 2;
bg = params[i] & 0xff;
}
} else if (p === 100) {
fg = (this.defAttr >> 9) & 0x1ff;
bg = this.defAttr & 0x1ff;
} else {
this.error("Unknown SGR attribute: %d.", p);
}
i++;
}
return this.curAttr = (flags << 18) | (fg << 9) | bg;
};
BackTerminal.prototype.deviceStatus = function(params) {
if (!this.prefix) {
switch (params[0]) {
case 5:
return this.send("\x1b[0n");
case 6:
return this.send("\x1b[" + (this.y + 1) + ";" + (this.x + 1) + "R");
}
} else if (this.prefix === "?") {
if (params[0] === 6) {
return this.send("\x1b[?" + (this.y + 1) + ";" + (this.x + 1) + "R");
}
}
};
BackTerminal.prototype.insertChars = function(params) {
var ch, j, param, row, _results;
param = params[0];
if (param < 1) {
param = 1;
}
row = this.y + this.ybase;
j = this.x;
ch = [this.eraseAttr(), " "];
_results = [];
while (param-- && j < this.cols) {
this.lines[row].splice(j++, 0, ch);
_results.push(this.lines[row].pop());
}
return _results;
};
BackTerminal.prototype.cursorNextLine = function(params) {
var param;
param = params[0];
if (param < 1) {
param = 1;
}
this.y += param;
if (this.y >= this.rows) {
this.y = this.rows - 1;
}
return this.x = 0;
};
BackTerminal.prototype.cursorPrecedingLine = function(params) {
var param;
param = params[0];
if (param < 1) {
param = 1;
}
this.y -= param;
if (this.y < 0) {
this.y = 0;
}
return this.x = 0;
};
BackTerminal.prototype.cursorCharAbsolute = function(params) {
var param;
param = params[0];
if (param < 1) {
param = 1;
}
return this.x = param - 1;
};
BackTerminal.prototype.insertLines = function(params) {
var j, param, row;
param = params[0];
if (param < 1) {
param = 1;
}
row = this.y + this.ybase;
j = this.rows - 1 - this.scrollBottom;
j = this.rows - 1 + this.ybase - j + 1;
while (param--) {
this.lines.splice(row, 0, this.blankLine(true));
this.lines.splice(j, 1);
}
this.updateRange(this.y);
return this.updateRange(this.scrollBottom);
};
BackTerminal.prototype.deleteLines = function(params) {
var j, param, row;
param = params[0];
if (param < 1) {
param = 1;
}
row = this.y + this.ybase;
j = this.rows - 1 - this.scrollBottom;
j = this.rows - 1 + this.ybase - j;
while (param--) {
this.lines.splice(j + 1, 0, this.blankLine(true));
this.lines.splice(row, 1);
}
this.updateRange(this.y);
return this.updateRange(this.scrollBottom);
};
BackTerminal.prototype.deleteChars = function(params) {
var ch, param, row, _results;
param = params[0];
if (param < 1) {
param = 1;
}
row = this.y + this.ybase;
ch = [this.eraseAttr(), " "];
_results = [];
while (param--) {
this.lines[row].splice(this.x, 1);
_results.push(this.lines[row].push(ch));
}
return _results;
};
BackTerminal.prototype.eraseChars = function(params) {
var ch, j, param, row, _results;
param = params[0];
if (param < 1) {
param = 1;
}
row = this.y + this.ybase;
j = this.x;
ch = [this.eraseAttr(), " "];
_results = [];
while (param-- && j < this.cols) {
_results.push(this.lines[row][j++] = ch);
}
return _results;
};
BackTerminal.prototype.charPosAbsolute = function(params) {
var param;
param = params[0];
if (param < 1) {
param = 1;
}
this.x = param - 1;
if (this.x >= this.cols) {
return this.x = this.cols - 1;
}
};
BackTerminal.prototype.HPositionRelative = function(params) {
var param;
param = params[0];
if (param < 1) {
param = 1;
}
this.x += param;
if (this.x >= this.cols) {
return this.x = this.cols - 1;
}
};
BackTerminal.prototype.sendDeviceAttributes = function(params) {
if (params[0] > 0) {
return;
}
if (!this.prefix) {
if (this.isterm("xterm") || this.isterm("rxvt-unicode") || this.isterm("screen")) {
return this.send("\x1b[?1;2c");
} else {
if (this.isterm("linux")) {
return this.send("\x1b[?6c");
}
}
} else if (this.prefix === ">") {
if (this.isterm("xterm")) {
return this.send("\x1b[>0;276;0c");
} else if (this.isterm("rxvt-unicode")) {
return this.send("\x1b[>85;95;0c");
} else if (this.isterm("linux")) {
return this.send(params[0] + "c");
} else {
if (this.isterm("screen")) {
return this.send("\x1b[>83;40003;0c");
}
}
}
};
BackTerminal.prototype.linePosAbsolute = function(params) {
var param;
param = params[0];
if (param < 1) {
param = 1;
}
this.y = param - 1;
if (this.y >= this.rows) {
return this.y = this.rows - 1;
}
};
BackTerminal.prototype.VPositionRelative = function(params) {
var param;
param = params[0];
if (param < 1) {
param = 1;
}
this.y += param;
if (this.y >= this.rows) {
return this.y = this.rows - 1;
}
};
BackTerminal.prototype.HVPosition = function(params) {
if (params[0] < 1) {
params[0] = 1;
}
if (params[1] < 1) {
params[1] = 1;
}
this.y = params[0] - 1;
if (this.y >= this.rows) {
this.y = this.rows - 1;
}
this.x = params[1] - 1;
if (this.x >= this.cols) {
return this.x = this.cols - 1;
}
};
BackTerminal.prototype.setMode = function(params) {
var i, l, normal;
if (typeof params === "object") {
l = params.length;
i = 0;
while (i < l) {
this.setMode(params[i]);
i++;
}
return;
}
if (this.prefix === "?") {
switch (params) {
case 1:
return this.applicationCursor = true;
case 2:
this.setgCharset(0, BackTerminal.prototype.charsets.US);
this.setgCharset(1, BackTerminal.prototype.charsets.US);
this.setgCharset(2, BackTerminal.prototype.charsets.US);
return this.setgCharset(3, BackTerminal.prototype.charsets.US);
case 3:
this.savedCols = this.cols;
return this.resize(132, this.rows);
case 6:
return this.originMode = true;
case 7:
return this.wraparoundMode = true;
case 66:
return this.applicationKeypad = true;
case 9:
case 1000:
case 1002:
case 1003:
this.x10Mouse = params === 9;
this.vt200Mouse = params === 1000;
this.normalMouse = params > 1000;
this.mouseEvents = true;
return this.element.style.cursor = "default";
case 1004:
return this.sendFocus = true;
case 1005:
return this.utfMouse = true;
case 1006:
return this.sgrMouse = true;
case 1015:
return this.urxvtMouse = true;
case 25:
return this.cursorHidden = false;
case 1049:
case 47:
case 1047:
if (!this.normal) {
normal = {
lines: this.lines,
ybase: this.ybase,
ydisp: this.ydisp,
x: this.x,
y: this.y,
scrollTop: this.scrollTop,
scrollBottom: this.scrollBottom,
tabs: this.tabs
};
this.reset();
this.normal = normal;
return this.showCursor();
}
}
}
};
BackTerminal.prototype.resetMode = function(params) {
var i, l;
if (typeof params === "object") {
l = params.length;
i = 0;
while (i < l) {
this.resetMode(params[i]);
i++;
}
return;
}
if (this.prefix === "?") {
switch (params) {
case 1:
return this.applicationCursor = false;
case 3:
if (this.cols === 132 && this.savedCols) {
this.resize(this.savedCols, this.rows);
}
return delete this.savedCols;
case 6:
return this.originMode = false;
case 7:
return this.wraparoundMode = false;
case 66:
return this.applicationKeypad = false;
case 9:
case 1000:
case 1002:
case 1003:
this.x10Mouse = false;
this.vt200Mouse = false;
this.normalMouse = false;
this.mouseEvents = false;
return this.element.style.cursor = "";
case 1004:
return this.sendFocus = false;
case 1005:
return this.utfMouse = false;
case 1006:
return this.sgrMouse = false;
case 1015:
return this.urxvtMouse = false;
case 25:
return this.cursorHidden = true;
case 1049:
case 47:
case 1047:
if (this.normal) {
this.lines = this.normal.lines;
this.ybase = this.normal.ybase;
this.ydisp = this.normal.ydisp;
this.x = this.normal.x;
this.y = this.normal.y;
this.scrollTop = this.normal.scrollTop;
this.scrollBottom = this.normal.scrollBottom;
this.tabs = this.normal.tabs;
this.normal = null;
this.refresh(0, this.rows - 1);
return this.showCursor();
}
}
}
};
BackTerminal.prototype.setScrollRegion = function(params) {
if (this.prefix) {
return;
}
this.scrollTop = (params[0] || 1) - 1;
this.scrollBottom = (params[1] || this.rows) - 1;
this.x = 0;
return this.y = 0;
};
BackTerminal.prototype.saveCursor = function(params) {
this.savedX = this.x;
return this.savedY = this.y;
};
BackTerminal.prototype.restoreCursor = function(params) {
this.x = this.savedX || 0;
return this.y = this.savedY || 0;
};
BackTerminal.prototype.cursorForwardTab = function(params) {
var param, _results;
param = params[0] || 1;
_results = [];
while (param--) {
_results.push(this.x = this.nextStop());
}
return _results;
};
BackTerminal.prototype.scrollUp = function(params) {
var param;
param = params[0] || 1;
while (param--) {
this.lines.splice(this.ybase + this.scrollTop, 1);
this.lines.splice(this.ybase + this.scrollBottom, 0, this.blankLine());
}
this.updateRange(this.scrollTop);
return this.updateRange(this.scrollBottom);
};
BackTerminal.prototype.scrollDown = function(params) {
var param;
param = params[0] || 1;
while (param--) {
this.lines.splice(this.ybase + this.scrollBottom, 1);
this.lines.splice(this.ybase + this.scrollTop, 0, this.blankLine());
}
this.updateRange(this.scrollTop);
return this.updateRange(this.scrollBottom);
};
BackTerminal.prototype.initMouseTracking = function(params) {};
BackTerminal.prototype.resetTitleModes = function(params) {};
BackTerminal.prototype.cursorBackwardTab = function(params) {
var param, _results;
param = params[0] || 1;
_results = [];
while (param--) {
_results.push(this.x = this.prevStop());
}
return _results;
};
BackTerminal.prototype.repeatPrecedingCharacter = function(params) {
var ch, line, param, _results;
param = params[0] || 1;
line = this.lines[this.ybase + this.y];
ch = line[this.x - 1] || [this.defAttr, " "];
_results = [];
while (param--) {
_results.push(line[this.x++] = ch);
}
return _results;
};
BackTerminal.prototype.tabClear = function(params) {
var param;
param = params[0];
if (param <= 0) {
return delete this.tabs[this.x];
} else {
if (param === 3) {
return this.tabs = {};
}
}
};
BackTerminal.prototype.mediaCopy = function(params) {};
BackTerminal.prototype.setResources = function(params) {};
BackTerminal.prototype.disableModifiers = function(params) {};
BackTerminal.prototype.setPointerMode = function(params) {};
BackTerminal.prototype.softReset = function(params) {
this.cursorHidden = false;
this.insertMode = false;
this.originMode = false;
this.wraparoundMode = false;
this.applicationKeypad = false;
this.applicationCursor = false;
this.scrollTop = 0;
this.scrollBottom = this.rows - 1;
this.curAttr = this.defAttr;
this.x = this.y = 0;
this.charset = null;
this.glevel = 0;
return this.charsets = [null];
};
BackTerminal.prototype.requestAnsiMode = function(params) {};
BackTerminal.prototype.requestPrivateMode = function(params) {};
BackTerminal.prototype.setConformanceLevel = function(params) {};
BackTerminal.prototype.loadLEDs = function(params) {};
BackTerminal.prototype.setCursorStyle = function(params) {};
BackTerminal.prototype.setCharProtectionAttr = function(params) {};
BackTerminal.prototype.restorePrivateValues = function(params) {};
BackTerminal.prototype.setAttrInRectangle = function(params) {
var attr, b, i, l, line, r, t;
t = params[0];
l = params[1];
b = params[2];
r = params[3];
attr = params[4];
while (t < b + 1) {
line = this.lines[this.ybase + t];
i = l;
while (i < r) {
line[i] = [attr, line[i][1]];
i++;
}
t++;
}
this.updateRange(params[0]);
return this.updateRange(params[2]);
};
BackTerminal.prototype.savePrivateValues = function(params) {};
BackTerminal.prototype.manipulateWindow = function(params) {};
BackTerminal.prototype.reverseAttrInRectangle = function(params) {};
BackTerminal.prototype.setTitleModeFeature = function(params) {};
BackTerminal.prototype.setWarningBellVolume = function(params) {};
BackTerminal.prototype.setMarginBellVolume = function(params) {};
BackTerminal.prototype.copyRectangle = function(params) {};
BackTerminal.prototype.enableFilterRectangle = function(params) {};
BackTerminal.prototype.requestParameters = function(params) {};
BackTerminal.prototype.selectChangeExtent = function(params) {};
BackTerminal.prototype.fillRectangle = function(params) {
var b, ch, i, l, line, r, t;
ch = params[0];
t = params[1];
l = params[2];
b = params[3];
r = params[4];
while (t < b + 1) {
line = this.lines[this.ybase + t];
i = l;
while (i < r) {
line[i] = [line[i][0], String.fromCharCode(ch)];
i++;
}
t++;
}
this.updateRange(params[1]);
return this.updateRange(params[3]);
};
BackTerminal.prototype.enableLocatorReporting = function(params) {
var val;
return val = params[0] > 0;
};
BackTerminal.prototype.eraseRectangle = function(params) {
var b, ch, i, l, line, r, t;
t = params[0];
l = params[1];
b = params[2];
r = params[3];
ch = [this.eraseAttr(), " "];
while (t < b + 1) {
line = this.lines[this.ybase + t];
i = l;
while (i < r) {
line[i] = ch;
i++;
}
t++;
}
this.updateRange(params[0]);
return this.updateRange(params[2]);
};
BackTerminal.prototype.setLocatorEvents = function(params) {};
BackTerminal.prototype.selectiveEraseRectangle = function(params) {};
BackTerminal.prototype.requestLocatorPosition = function(params) {};
BackTerminal.prototype.insertColumns = function() {
var ch, i, l, param;
param = params[0];
l = this.ybase + this.rows;
ch = [this.eraseAttr(), " "];
while (param--) {
i = this.ybase;
while (i < l) {
this.lines[i].splice(this.x + 1, 0, ch);
this.lines[i].pop();
i++;
}
}
return this.maxRange();
};
BackTerminal.prototype.deleteColumns = function() {
var ch, i, l, param;
param = params[0];
l = this.ybase + this.rows;
ch = [this.eraseAttr(), " "];
while (param--) {
i = this.ybase;
while (i < l) {
this.lines[i].splice(this.x, 1);
this.lines[i].push(ch);
i++;
}
}
return this.maxRange();
};
BackTerminal.prototype.charsets = {
SCLD: {
"`": "◆",
a: "▒",
b: "\t",
c: "\f",
d: "\r",
e: "\n",
f: "°",
g: "±",
h: "␤",
i: "\x0b",
j: "┘",
k: "┐",
l: "┌",
m: "└",
n: "┼",
o: "⎺",
p: "⎻",
q: "─",
r: "⎼",
s: "⎽",
t: "├",
u: "┤",
v: "┴",
w: "┬",
x: "│",
y: "≤",
z: "≥",
"{": "π",
"|": "≠",
"}": "£",
"~": "·"
},
UK: null,
US: null,
Dutch: null,
Finnish: null,
French: null,
FrenchCanadian: null,
German: null,
Italian: null,
NorwegianDanish: null,
Spanish: null,
Swedish: null,
Swiss: null,
ISOLatin: null
};
return BackTerminal;
})();