Handle more CSI codes

openid
Marcin Kulik 13 years ago
parent ef08c5079c
commit 00297cc8bf

@ -61,23 +61,52 @@ SP.AnsiInterpreter.prototype = {
// l = Resets mode (http://ttssh2.sourceforge.jp/manual/en/about/ctrlseq.html#mode)
// 1001 + s = ?
// 1001 + r = ?
if (match[1] == '1049') {
if (match[2] == 'h') {
// 1049 + h = Save cursor position, switch to alternate screen buffer, and clear screen.
this.terminal.saveCursor();
this.terminal.switchToAlternateBuffer();
this.terminal.clearScreen();
} else if (match[2] == 'l') {
// 1049 + l = Clear screen, switch to normal screen buffer, and restore cursor position.
this.terminal.clearScreen();
this.terminal.switchToNormalBuffer();
this.terminal.restoreCursor();
var modes = match[1].split(';');
var action = match[2];
var mode;
for (var i=0; i<modes.length; i++) {
mode = modes[i];
if (mode == '1049') {
if (action == 'h') {
// Save cursor position, switch to alternate screen buffer, and clear screen.
this.terminal.saveCursor();
this.terminal.switchToAlternateBuffer();
this.terminal.clearScreen();
} else if (action == 'l') {
// Clear screen, switch to normal screen buffer, and restore cursor position.
this.terminal.clearScreen();
this.terminal.switchToNormalBuffer();
this.terminal.restoreCursor();
}
} else if (mode == '1002') {
// 2002 + h / l = mouse tracking stuff
} else if (mode == '1001') {
// pbly sth with mouse/keys...
} else if (mode == '1') {
// 1 + h / l = cursor keys stuff
} else if (mode == '47') {
if (action == 'h') {
this.terminal.switchToAlternateBuffer();
} else if (action == 'l') {
this.terminal.switchToNormalBuffer();
}
} else if (mode == '25') {
if (action == 'h') {
this.terminal.showCursor(true);
} else if (action == 'l') {
this.terminal.showCursor(false);
}
} else if (mode == '12') {
if (action == 'h') {
// blinking cursor
} else if (action == 'l') {
// steady cursor
}
} else {
throw 'unknown mode: ' + mode + action;
}
} else if (match[1] == '1002') {
// 2002 + h / l = mouse tracking stuff
} else if (match[1] == '1') {
// 1 + h / l = cursor keys stuff
}
},
@ -96,6 +125,10 @@ SP.AnsiInterpreter.prototype = {
"\x1bP([^\\\\])*?\\\\": function(data) { // DCS, Device Control String
},
"\x1bM": function() {
this.terminal.ri(this.n || 1);
},
"\x1b\x37": function(data) { // save cursor pos and char attrs
this.terminal.saveCursor();
},
@ -131,6 +164,9 @@ SP.AnsiInterpreter.prototype = {
case "K":
this.terminal.eraseLine(this.n || 0);
break;
case "L":
this.terminal.insertLines(this.cursorY, this.n || 1);
break;
case "l": // l, Reset mode
console.log("(TODO) reset: " + this.n);
break;
@ -140,7 +176,7 @@ SP.AnsiInterpreter.prototype = {
case "r": // Set top and bottom margins (scroll region on VT100)
break;
default:
console.log('no handler for CSI term: ' + term);
throw 'no handler for CSI term: ' + term;
}
},

@ -94,6 +94,14 @@ SP.Terminal.prototype = {
}
},
showCursor: function(show) {
if (show) {
this.element.addClass('cursor-on');
} else {
this.element.removeClass('cursor-on');
}
},
setSGR: function(codes) {
if (codes.length == 0) {
codes = [0];
@ -250,12 +258,37 @@ SP.Terminal.prototype = {
}
},
clearLineData: function(n) {
this.fill(n, 0, this.cols, ' ');
},
reserveCharacters: function(n) {
var line = this.getLine();
this.lineData[this.cursorLine] = line.slice(0, this.cursorCol).concat(" ".times(n).split(''), line.slice(this.cursorCol, this.cols - n));
this.updateLine();
},
ri: function(n) {
for (var i=0; i<n; i++) {
if (this.cursorY == 0) {
this.insertLines(0, n);
} else {
this.cursorUp();
}
}
},
insertLines: function(l, n) {
for (var i=0; i<n; i++) {
this.lineData.splice(l, 0, []);
this.clearLineData(l);
}
this.lineData.length = this.lines;
this.updateScreen();
},
fill: function(line, col, n, char) {
var prefix = '', postfix = '';

@ -32,11 +32,11 @@
/* margin: 0;*/
}
.line span.cursor, .line .cursor > span {
.cursor-on .line span.cursor, .cursor-on .line .cursor > span {
background-color: #D3D7CF;
}
.line span.cursor.inverted, .line .cursor.inverted > span {
.cursor-on .line span.cursor.inverted, .cursor-on .line .cursor.inverted > span {
background-color: inherit;
}

Loading…
Cancel
Save