update files

This commit is contained in:
nuintun 2015-11-24 22:00:46 +08:00
parent 085a5cf350
commit 32ae3adceb
24 changed files with 149 additions and 142 deletions

View File

@ -7,10 +7,9 @@
module.exports = function (Terminal){ module.exports = function (Terminal){
Terminal.prototype.blankLine = function (cur){ Terminal.prototype.blankLine = function (cur){
var attr = cur ? this.curAttr : this.defAttr; var attr = cur ? this.curAttr : this.defAttr;
var ch = [attr, ' '];
var ch = [attr, ' '], var line = [];
line = [], var i = 0;
i = 0;
for (; i < this.cols; i++) { for (; i < this.cols; i++) {
line[i] = ch; line[i] = ch;

View File

@ -5,9 +5,7 @@
'use strict'; 'use strict';
module.exports = function (Terminal){ module.exports = function (Terminal){
Terminal.charsets = {}; Terminal.charsets = {};
// DEC Special Character and Line Drawing Set. // DEC Special Character and Line Drawing Set.
// http://vt100.net/docs/vt102-ug/table5-13.html // http://vt100.net/docs/vt102-ug/table5-13.html
// A lot of curses apps use this if they see TERM=xterm. // A lot of curses apps use this if they see TERM=xterm.
@ -49,7 +47,6 @@ module.exports = function (Terminal){
'}': '\u00a3', // '£' '}': '\u00a3', // '£'
'~': '\u00b7' // '·' '~': '\u00b7' // '·'
}; };
Terminal.charsets.UK = null; // (A Terminal.charsets.UK = null; // (A
Terminal.charsets.US = null; // (B (USASCII) Terminal.charsets.US = null; // (B (USASCII)
Terminal.charsets.Dutch = null; // (4 Terminal.charsets.Dutch = null; // (4
@ -63,5 +60,4 @@ module.exports = function (Terminal){
Terminal.charsets.Swedish = null; // (H or (7 Terminal.charsets.Swedish = null; // (H or (7
Terminal.charsets.Swiss = null; // (= Terminal.charsets.Swiss = null; // (=
Terminal.charsets.ISOLatin = null; // /A Terminal.charsets.ISOLatin = null; // /A
}; };

View File

@ -5,7 +5,6 @@
'use strict'; 'use strict';
module.exports = function (Terminal){ module.exports = function (Terminal){
// Colors 0-15 // Colors 0-15
Terminal.colors = [ Terminal.colors = [
// dark: // dark:
@ -13,22 +12,24 @@ module.exports = function (Terminal){
// bright: // bright:
'#555753', '#ef2929', '#8ae234', '#fce94f', '#729fcf', '#ad7fa8', '#34e2e2', '#eeeeec' '#555753', '#ef2929', '#8ae234', '#fce94f', '#729fcf', '#ad7fa8', '#34e2e2', '#eeeeec'
]; ];
// Colors 16-255 // Colors 16-255
// Much thanks to TooTallNate for writing this. // Much thanks to TooTallNate for writing this.
Terminal.colors = (function (){ Terminal.colors = (function (){
var colors = Terminal.colors, var colors = Terminal.colors;
r = [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff], var r = [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff];
i; var i;
// 16-231 // 16-231
i = 0; i = 0;
for (; i < 216; i++) { for (; i < 216; i++) {
out(r[(i / 36) % 6 | 0], r[(i / 6) % 6 | 0], r[i % 6]); out(r[(i / 36) % 6 | 0], r[(i / 6) % 6 | 0], r[i % 6]);
} }
// 232-255 (grey) // 232-255 (grey)
i = 0; i = 0;
for (; i < 24; i++) { for (; i < 24; i++) {
r = 8 + i * 10; r = 8 + i * 10;
out(r, r, r); out(r, r, r);
@ -40,6 +41,7 @@ module.exports = function (Terminal){
function hex(c){ function hex(c){
c = c.toString(16); c = c.toString(16);
return c.length < 2 ? '0' + c : c; return c.length < 2 ? '0' + c : c;
} }

View File

@ -5,7 +5,6 @@
'use strict'; 'use strict';
module.exports = function (Terminal){ module.exports = function (Terminal){
// CSI Pm m Character Attributes (SGR). // CSI Pm m Character Attributes (SGR).
// Ps = 0 -> Normal (default). // Ps = 0 -> Normal (default).
// Ps = 1 -> Bold. // Ps = 1 -> Bold.

View File

@ -7,14 +7,14 @@
module.exports = function (Terminal){ module.exports = function (Terminal){
// CSI s // CSI s
// Save cursor (ANSI.SYS). // Save cursor (ANSI.SYS).
Terminal.prototype.saveCursor = function (params){ Terminal.prototype.saveCursor = function (){
this.savedX = this.x; this.savedX = this.x;
this.savedY = this.y; this.savedY = this.y;
}; };
// CSI u // CSI u
// Restore cursor (ANSI.SYS). // Restore cursor (ANSI.SYS).
Terminal.prototype.restoreCursor = function (params){ Terminal.prototype.restoreCursor = function (){
this.x = this.savedX || 0; this.x = this.savedX || 0;
this.y = this.savedY || 0; this.y = this.savedY || 0;
}; };
@ -23,8 +23,11 @@ module.exports = function (Terminal){
// Cursor Up Ps Times (default = 1) (CUU). // Cursor Up Ps Times (default = 1) (CUU).
Terminal.prototype.cursorUp = function (params){ Terminal.prototype.cursorUp = function (params){
var param = params[0]; var param = params[0];
if (param < 1) param = 1; if (param < 1) param = 1;
this.y -= param; this.y -= param;
if (this.y < 0) this.y = 0; if (this.y < 0) this.y = 0;
}; };
@ -32,8 +35,11 @@ module.exports = function (Terminal){
// Cursor Down Ps Times (default = 1) (CUD). // Cursor Down Ps Times (default = 1) (CUD).
Terminal.prototype.cursorDown = function (params){ Terminal.prototype.cursorDown = function (params){
var param = params[0]; var param = params[0];
if (param < 1) param = 1; if (param < 1) param = 1;
this.y += param; this.y += param;
if (this.y >= this.rows) { if (this.y >= this.rows) {
this.y = this.rows - 1; this.y = this.rows - 1;
} }
@ -43,8 +49,11 @@ module.exports = function (Terminal){
// Cursor Forward Ps Times (default = 1) (CUF). // Cursor Forward Ps Times (default = 1) (CUF).
Terminal.prototype.cursorForward = function (params){ Terminal.prototype.cursorForward = function (params){
var param = params[0]; var param = params[0];
if (param < 1) param = 1; if (param < 1) param = 1;
this.x += param; this.x += param;
if (this.x >= this.cols) { if (this.x >= this.cols) {
this.x = this.cols - 1; this.x = this.cols - 1;
} }
@ -54,8 +63,11 @@ module.exports = function (Terminal){
// Cursor Backward Ps Times (default = 1) (CUB). // Cursor Backward Ps Times (default = 1) (CUB).
Terminal.prototype.cursorBackward = function (params){ Terminal.prototype.cursorBackward = function (params){
var param = params[0]; var param = params[0];
if (param < 1) param = 1; if (param < 1) param = 1;
this.x -= param; this.x -= param;
if (this.x < 0) this.x = 0; if (this.x < 0) this.x = 0;
}; };
@ -93,11 +105,15 @@ module.exports = function (Terminal){
// same as CSI Ps B ? // same as CSI Ps B ?
Terminal.prototype.cursorNextLine = function (params){ Terminal.prototype.cursorNextLine = function (params){
var param = params[0]; var param = params[0];
if (param < 1) param = 1; if (param < 1) param = 1;
this.y += param; this.y += param;
if (this.y >= this.rows) { if (this.y >= this.rows) {
this.y = this.rows - 1; this.y = this.rows - 1;
} }
this.x = 0; this.x = 0;
}; };
@ -106,9 +122,13 @@ module.exports = function (Terminal){
// reuse CSI Ps A ? // reuse CSI Ps A ?
Terminal.prototype.cursorPrecedingLine = function (params){ Terminal.prototype.cursorPrecedingLine = function (params){
var param = params[0]; var param = params[0];
if (param < 1) param = 1; if (param < 1) param = 1;
this.y -= param; this.y -= param;
if (this.y < 0) this.y = 0; if (this.y < 0) this.y = 0;
this.x = 0; this.x = 0;
}; };
@ -116,7 +136,9 @@ module.exports = function (Terminal){
// Cursor Character Absolute [column] (default = [row,1]) (CHA). // Cursor Character Absolute [column] (default = [row,1]) (CHA).
Terminal.prototype.cursorCharAbsolute = function (params){ Terminal.prototype.cursorCharAbsolute = function (params){
var param = params[0]; var param = params[0];
if (param < 1) param = 1; if (param < 1) param = 1;
this.x = param - 1; this.x = param - 1;
}; };
@ -124,6 +146,7 @@ module.exports = function (Terminal){
// Cursor Forward Tabulation Ps tab stops (default = 1) (CHT). // Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
Terminal.prototype.cursorForwardTab = function (params){ Terminal.prototype.cursorForwardTab = function (params){
var param = params[0] || 1; var param = params[0] || 1;
while (param--) { while (param--) {
this.x = this.nextStop(); this.x = this.nextStop();
} }
@ -132,9 +155,9 @@ module.exports = function (Terminal){
// CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT). // CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
Terminal.prototype.cursorBackwardTab = function (params){ Terminal.prototype.cursorBackwardTab = function (params){
var param = params[0] || 1; var param = params[0] || 1;
while (param--) { while (param--) {
this.x = this.prevStop(); this.x = this.prevStop();
} }
}; };
}; };

View File

@ -12,6 +12,7 @@ module.exports = function (Terminal){
var param, row, j, ch; var param, row, j, ch;
param = params[0]; param = params[0];
if (param < 1) param = 1; if (param < 1) param = 1;
row = this.y + this.ybase; row = this.y + this.ybase;
@ -30,9 +31,10 @@ module.exports = function (Terminal){
var param, row, j; var param, row, j;
param = params[0]; param = params[0];
if (param < 1) param = 1;
row = this.y + this.ybase;
if (param < 1) param = 1;
row = this.y + this.ybase;
j = this.rows - 1 - this.scrollBottom; j = this.rows - 1 - this.scrollBottom;
j = this.rows - 1 + this.ybase - j + 1; j = this.rows - 1 + this.ybase - j + 1;
@ -54,9 +56,10 @@ module.exports = function (Terminal){
var param, row, j; var param, row, j;
param = params[0]; param = params[0];
if (param < 1) param = 1;
row = this.y + this.ybase;
if (param < 1) param = 1;
row = this.y + this.ybase;
j = this.rows - 1 - this.scrollBottom; j = this.rows - 1 - this.scrollBottom;
j = this.rows - 1 + this.ybase - j; j = this.rows - 1 + this.ybase - j;
@ -78,6 +81,7 @@ module.exports = function (Terminal){
var param, row, ch; var param, row, ch;
param = params[0]; param = params[0];
if (param < 1) param = 1; if (param < 1) param = 1;
row = this.y + this.ybase; row = this.y + this.ybase;
@ -95,6 +99,7 @@ module.exports = function (Terminal){
var param, row, j, ch; var param, row, j, ch;
param = params[0]; param = params[0];
if (param < 1) param = 1; if (param < 1) param = 1;
row = this.y + this.ybase; row = this.y + this.ybase;

View File

@ -9,8 +9,11 @@ module.exports = function (Terminal){
// [column] (default = [row,1]) (HPA). // [column] (default = [row,1]) (HPA).
Terminal.prototype.charPosAbsolute = function (params){ Terminal.prototype.charPosAbsolute = function (params){
var param = params[0]; var param = params[0];
if (param < 1) param = 1; if (param < 1) param = 1;
this.x = param - 1; this.x = param - 1;
if (this.x >= this.cols) { if (this.x >= this.cols) {
this.x = this.cols - 1; this.x = this.cols - 1;
} }
@ -21,8 +24,11 @@ module.exports = function (Terminal){
// reuse CSI Ps C ? // reuse CSI Ps C ?
Terminal.prototype.HPositionRelative = function (params){ Terminal.prototype.HPositionRelative = function (params){
var param = params[0]; var param = params[0];
if (param < 1) param = 1; if (param < 1) param = 1;
this.x += param; this.x += param;
if (this.x >= this.cols) { if (this.x >= this.cols) {
this.x = this.cols - 1; this.x = this.cols - 1;
} }
@ -32,8 +38,11 @@ module.exports = function (Terminal){
// Line Position Absolute [row] (default = [1,column]) (VPA). // Line Position Absolute [row] (default = [1,column]) (VPA).
Terminal.prototype.linePosAbsolute = function (params){ Terminal.prototype.linePosAbsolute = function (params){
var param = params[0]; var param = params[0];
if (param < 1) param = 1; if (param < 1) param = 1;
this.y = param - 1; this.y = param - 1;
if (this.y >= this.rows) { if (this.y >= this.rows) {
this.y = this.rows - 1; this.y = this.rows - 1;
} }
@ -43,8 +52,11 @@ module.exports = function (Terminal){
// reuse CSI Ps B ? // reuse CSI Ps B ?
Terminal.prototype.VPositionRelative = function (params){ Terminal.prototype.VPositionRelative = function (params){
var param = params[0]; var param = params[0];
if (param < 1) param = 1; if (param < 1) param = 1;
this.y += param; this.y += param;
if (this.y >= this.rows) { if (this.y >= this.rows) {
this.y = this.rows - 1; this.y = this.rows - 1;
} }
@ -55,14 +67,17 @@ module.exports = function (Terminal){
// [1,1]) (HVP). // [1,1]) (HVP).
Terminal.prototype.HVPosition = function (params){ Terminal.prototype.HVPosition = function (params){
if (params[0] < 1) params[0] = 1; if (params[0] < 1) params[0] = 1;
if (params[1] < 1) params[1] = 1; if (params[1] < 1) params[1] = 1;
this.y = params[0] - 1; this.y = params[0] - 1;
if (this.y >= this.rows) { if (this.y >= this.rows) {
this.y = this.rows - 1; this.y = this.rows - 1;
} }
this.x = params[1] - 1; this.x = params[1] - 1;
if (this.x >= this.cols) { if (this.x >= this.cols) {
this.x = this.cols - 1; this.x = this.cols - 1;
} }

View File

@ -7,9 +7,9 @@
module.exports = function (Terminal){ module.exports = function (Terminal){
// CSI Ps b Repeat the preceding graphic character Ps times (REP). // CSI Ps b Repeat the preceding graphic character Ps times (REP).
Terminal.prototype.repeatPrecedingCharacter = function (params){ Terminal.prototype.repeatPrecedingCharacter = function (params){
var param = params[0] || 1, var param = params[0] || 1;
line = this.lines[this.ybase + this.y], var line = this.lines[this.ybase + this.y];
ch = line[this.x - 1] || [this.defAttr, ' ']; var ch = line[this.x - 1] || [this.defAttr, ' '];
while (param--) line[this.x++] = ch; while (param--) line[this.x++] = ch;
}; };

View File

@ -7,7 +7,7 @@
module.exports = function (Terminal){ module.exports = function (Terminal){
// CSI ! p Soft terminal reset (DECSTR). // CSI ! p Soft terminal reset (DECSTR).
// http://vt100.net/docs/vt220-rm/table4-10.html // http://vt100.net/docs/vt220-rm/table4-10.html
Terminal.prototype.softReset = function (params){ Terminal.prototype.softReset = function (){
this.cursorHidden = false; this.cursorHidden = false;
this.insertMode = false; this.insertMode = false;
this.originMode = false; this.originMode = false;

View File

@ -13,6 +13,7 @@ module.exports = function (Terminal){
// http://vt100.net/annarbor/aaa-ug/section6.html // http://vt100.net/annarbor/aaa-ug/section6.html
Terminal.prototype.tabClear = function (params){ Terminal.prototype.tabClear = function (params){
var param = params[0]; var param = params[0];
if (param <= 0) { if (param <= 0) {
delete this.tabs[this.x]; delete this.tabs[this.x];
} else if (param === 3) { } else if (param === 3) {

View File

@ -7,6 +7,7 @@
module.exports = function (Terminal){ module.exports = function (Terminal){
Terminal.prototype.cursorBlink = function (){ Terminal.prototype.cursorBlink = function (){
if (Terminal.focus !== this) return; if (Terminal.focus !== this) return;
this.cursorState ^= 1; this.cursorState ^= 1;
this.refresh(this.y, this.y); this.refresh(this.y, this.y);
}; };
@ -15,24 +16,26 @@ module.exports = function (Terminal){
if (!this.cursorState) { if (!this.cursorState) {
this.cursorState = 1; this.cursorState = 1;
this.refresh(this.y, this.y); this.refresh(this.y, this.y);
} else {
// Temporarily disabled:
// this.refreshBlink();
} }
}; };
Terminal.prototype.startBlink = function (){ Terminal.prototype.startBlink = function (){
if (!Terminal.cursorBlink) return; if (!Terminal.cursorBlink) return;
var self = this; var self = this;
this._blinker = function (){ this._blinker = function (){
self.cursorBlink(); self.cursorBlink();
}; };
this._blink = setInterval(this._blinker, 500); this._blink = setInterval(this._blinker, 500);
}; };
Terminal.prototype.refreshBlink = function (){ Terminal.prototype.refreshBlink = function (){
if (!Terminal.cursorBlink) return; if (!Terminal.cursorBlink) return;
clearInterval(this._blink); clearInterval(this._blink);
this._blink = setInterval(this._blinker, 500); this._blink = setInterval(this._blinker, 500);
}; };
}; };

View File

@ -7,15 +7,21 @@
module.exports = function (Terminal){ module.exports = function (Terminal){
Terminal.prototype.log = function (){ Terminal.prototype.log = function (){
if (!Terminal.debug) return; if (!Terminal.debug) return;
if (!window.console || !window.console.log) return; if (!window.console || !window.console.log) return;
var args = Array.prototype.slice.call(arguments); var args = Array.prototype.slice.call(arguments);
window.console.log.apply(window.console, args); window.console.log.apply(window.console, args);
}; };
Terminal.prototype.error = function (){ Terminal.prototype.error = function (){
if (!Terminal.debug) return; if (!Terminal.debug) return;
if (!window.console || !window.console.error) return; if (!window.console || !window.console.error) return;
var args = Array.prototype.slice.call(arguments); var args = Array.prototype.slice.call(arguments);
window.console.error.apply(window.console, args); window.console.error.apply(window.console, args);
}; };
}; };

View File

@ -6,8 +6,8 @@
module.exports = function (Terminal){ module.exports = function (Terminal){
Terminal.prototype.eraseRight = function (x, y){ Terminal.prototype.eraseRight = function (x, y){
var line = this.lines[this.ybase + y], var line = this.lines[this.ybase + y];
ch = [this.curAttr, ' ']; // xterm var ch = [this.curAttr, ' ']; // xterm
for (; x < this.cols; x++) { for (; x < this.cols; x++) {
line[x] = ch; line[x] = ch;
@ -17,10 +17,11 @@ module.exports = function (Terminal){
}; };
Terminal.prototype.eraseLeft = function (x, y){ Terminal.prototype.eraseLeft = function (x, y){
var line = this.lines[this.ybase + y], var line = this.lines[this.ybase + y];
ch = [this.curAttr, ' ']; // xterm var ch = [this.curAttr, ' ']; // xterm
x++; x++;
while (x--) line[x] = ch; while (x--) line[x] = ch;
this.updateRange(y); this.updateRange(y);
@ -42,27 +43,33 @@ module.exports = function (Terminal){
// Ps = 2 -> Selective Erase All. // Ps = 2 -> Selective Erase All.
Terminal.prototype.eraseInDisplay = function (params){ Terminal.prototype.eraseInDisplay = function (params){
var j; var j;
switch (params[0]) { switch (params[0]) {
case 0: case 0:
this.eraseRight(this.x, this.y); this.eraseRight(this.x, this.y);
j = this.y + 1; j = this.y + 1;
for (; j < this.rows; j++) { for (; j < this.rows; j++) {
this.eraseLine(j); this.eraseLine(j);
} }
break; break;
case 1: case 1:
this.eraseLeft(this.x, this.y); this.eraseLeft(this.x, this.y);
j = this.y; j = this.y;
while (j--) { while (j--) {
this.eraseLine(j); this.eraseLine(j);
} }
break; break;
case 2: case 2:
j = this.rows; j = this.rows;
while (j--) this.eraseLine(j); while (j--) this.eraseLine(j);
break; break;
case 3: case 3:
; // no saved lines // no saved lines
break; break;
} }
}; };

View File

@ -3,35 +3,43 @@
*/ */
'use strict'; 'use strict';
var states = require('../states'); var states = require('../states');
module.exports = function (Terminal){ module.exports = function (Terminal){
// ESC D Index (IND is 0x84). // ESC D Index (IND is 0x84).
Terminal.prototype.index = function (){ Terminal.prototype.index = function (){
this.y++; this.y++;
if (this.y > this.scrollBottom) { if (this.y > this.scrollBottom) {
this.y--; this.y--;
this.scroll(); this.scroll();
} }
this.state = states.normal; this.state = states.normal;
}; };
// ESC M Reverse Index (RI is 0x8d). // ESC M Reverse Index (RI is 0x8d).
Terminal.prototype.reverseIndex = function (){ Terminal.prototype.reverseIndex = function (){
var j; var j;
this.y--; this.y--;
if (this.y < this.scrollTop) { if (this.y < this.scrollTop) {
this.y++; this.y++;
// possibly move the code below to term.reverseScroll(); // possibly move the code below to term.reverseScroll();
// test: echo -ne '\e[1;1H\e[44m\eM\e[0m' // test: echo -ne '\e[1;1H\e[44m\eM\e[0m'
// blankLine(true) is xterm/linux behavior // blankLine(true) is xterm/linux behavior
this.lines.splice(this.y + this.ybase, 0, this.blankLine(true)); this.lines.splice(this.y + this.ybase, 0, this.blankLine(true));
j = this.rows - 1 - this.scrollBottom; j = this.rows - 1 - this.scrollBottom;
this.lines.splice(this.rows - 1 + this.ybase - j + 1, 1); this.lines.splice(this.rows - 1 + this.ybase - j + 1, 1);
// this.maxRange();
this.updateRange(this.scrollTop); this.updateRange(this.scrollTop);
this.updateRange(this.scrollBottom); this.updateRange(this.scrollBottom);
} }
this.state = states.normal; this.state = states.normal;
}; };
}; };

View File

@ -5,7 +5,6 @@
'use strict'; 'use strict';
module.exports = function (Terminal){ module.exports = function (Terminal){
// ESC c Full Reset (RIS). // ESC c Full Reset (RIS).
Terminal.prototype.reset = function (){ Terminal.prototype.reset = function (){
Terminal.call(this, this.cols, this.rows); Terminal.call(this, this.cols, this.rows);

View File

@ -6,7 +6,6 @@
var states = require('../states'); var states = require('../states');
module.exports = function (Terminal){ module.exports = function (Terminal){
// ESC H Tab Set (HTS is 0x88). // ESC H Tab Set (HTS is 0x88).
Terminal.prototype.tabSet = function (){ Terminal.prototype.tabSet = function (){
this.tabs[this.x] = true; this.tabs[this.x] = true;

View File

@ -8,12 +8,19 @@
// use it in the terminal. // use it in the terminal.
function isBoldBroken(){ function isBoldBroken(){
var el = document.createElement('span'); var el = document.createElement('span');
el.innerHTML = 'hello world'; el.innerHTML = 'hello world';
document.body.appendChild(el); document.body.appendChild(el);
var w1 = el.scrollWidth; var w1 = el.scrollWidth;
el.style.fontWeight = 'bold'; el.style.fontWeight = 'bold';
var w2 = el.scrollWidth; var w2 = el.scrollWidth;
document.body.removeChild(el); document.body.removeChild(el);
return w1 !== w2; return w1 !== w2;
} }
@ -21,11 +28,9 @@ module.exports = function (Terminal){
/** /**
* Open Terminal * Open Terminal
*/ */
Terminal.prototype.open = function (){ Terminal.prototype.open = function (){
var self = this, var i = 0;
i = 0, var div;
div;
this.element = document.createElement('div'); this.element = document.createElement('div');
this.element.className = 'terminal'; this.element.className = 'terminal';
@ -33,6 +38,7 @@ module.exports = function (Terminal){
for (; i < this.rows; i++) { for (; i < this.rows; i++) {
div = document.createElement('div'); div = document.createElement('div');
this.element.appendChild(div); this.element.appendChild(div);
this.children.push(div); this.children.push(div);
} }

View File

@ -7,7 +7,9 @@
function addRowsOnDemand(){ function addRowsOnDemand(){
while (this.y >= this.rows) { while (this.y >= this.rows) {
this.lines.push(this.blankLine()); this.lines.push(this.blankLine());
var div = document.createElement('div'); var div = document.createElement('div');
this.element.appendChild(div); this.element.appendChild(div);
this.children.push(div); this.children.push(div);
@ -18,7 +20,9 @@ function addRowsOnDemand(){
module.exports = function (Terminal){ module.exports = function (Terminal){
Terminal.prototype.updateRange = function (y){ Terminal.prototype.updateRange = function (y){
if (y < this.refreshStart) this.refreshStart = y; if (y < this.refreshStart) this.refreshStart = y;
if (y > this.refreshEnd) this.refreshEnd = y; if (y > this.refreshEnd) this.refreshEnd = y;
addRowsOnDemand.bind(this)(); addRowsOnDemand.bind(this)();
}; };

View File

@ -5,7 +5,6 @@
'use strict'; 'use strict';
module.exports = function (Terminal){ module.exports = function (Terminal){
/** /**
* Rendering Engine * Rendering Engine
*/ */
@ -19,7 +18,6 @@ module.exports = function (Terminal){
// Next 9 bits: foreground color (0-511). // Next 9 bits: foreground color (0-511).
// Next 14 bits: a mask for misc. flags: // Next 14 bits: a mask for misc. flags:
// 1=bold, 2=underline, 4=inverse // 1=bold, 2=underline, 4=inverse
Terminal.prototype.refresh = function (start, end){ Terminal.prototype.refresh = function (start, end){
var x, y, i, line, out, ch, width, data, attr, fgColor, bgColor, flags, row, parent; var x, y, i, line, out, ch, width, data, attr, fgColor, bgColor, flags, row, parent;
@ -28,8 +26,8 @@ module.exports = function (Terminal){
for (; y <= end; y++) { for (; y <= end; y++) {
row = y + this.ydisp; row = y + this.ydisp;
line = this.lines[row]; line = this.lines[row];
if (!line) { if (!line) {
// simple solution in case we have more lines than rows // simple solution in case we have more lines than rows
// could be improved to instead remove first line (and related html element) // could be improved to instead remove first line (and related html element)
@ -57,6 +55,7 @@ module.exports = function (Terminal){
if (attr !== this.defAttr) { if (attr !== this.defAttr) {
out += '</span>'; out += '</span>';
} }
if (data !== this.defAttr) { if (data !== this.defAttr) {
if (data === -1) { if (data === -1) {
out += '<span class="reverse-video">'; out += '<span class="reverse-video">';
@ -71,6 +70,7 @@ module.exports = function (Terminal){
if (!Terminal.brokenBold) { if (!Terminal.brokenBold) {
out += 'font-weight:bold;'; out += 'font-weight:bold;';
} }
// see: XTerm*boldColors // see: XTerm*boldColors
if (fgColor < 8) fgColor += 8; if (fgColor < 8) fgColor += 8;
} }

View File

@ -7,6 +7,7 @@
module.exports = function (Terminal){ module.exports = function (Terminal){
Terminal.prototype.setgCharset = function (g, charset){ Terminal.prototype.setgCharset = function (g, charset){
this.charsets[g] = charset; this.charsets[g] = charset;
if (this.glevel === g) { if (this.glevel === g) {
this.charset = charset; this.charset = charset;
} }

View File

@ -5,11 +5,11 @@
'use strict'; 'use strict';
module.exports = { module.exports = {
normal: 0 normal: 0,
, escaped: 1 escaped: 1,
, csi: 2 csi: 2,
, osc: 3 osc: 3,
, charset: 4 charset: 4,
, dcs: 5 dcs: 5,
, ignore: 6 ignore: 6
}; };

View File

@ -6,7 +6,6 @@
// ignore warnings regarging == and != (coersion makes things work here appearently) // ignore warnings regarging == and != (coersion makes things work here appearently)
module.exports = function (Terminal){ module.exports = function (Terminal){
Terminal.prototype.setupStops = function (i){ Terminal.prototype.setupStops = function (i){
if (i != null) { if (i != null) {
if (!this.tabs[i]) { if (!this.tabs[i]) {
@ -24,13 +23,17 @@ module.exports = function (Terminal){
Terminal.prototype.prevStop = function (x){ Terminal.prototype.prevStop = function (x){
if (x == null) x = this.x; if (x == null) x = this.x;
while (!this.tabs[--x] && x > 0);
while (!this.tabs[--x] && x > 0) {}
return x >= this.cols ? this.cols - 1 : x < 0 ? 0 : x; return x >= this.cols ? this.cols - 1 : x < 0 ? 0 : x;
}; };
Terminal.prototype.nextStop = function (x){ Terminal.prototype.nextStop = function (x){
if (x == null) x = this.x; if (x == null) x = this.x;
while (!this.tabs[++x] && x < this.cols);
while (!this.tabs[++x] && x < this.cols) {}
return x >= this.cols ? this.cols - 1 : x < 0 ? 0 : x; return x >= this.cols ? this.cols - 1 : x < 0 ? 0 : x;
}; };
}; };

View File

@ -11,7 +11,7 @@ module.exports = function (Terminal){
Terminal.prototype.is = function (term){ Terminal.prototype.is = function (term){
var name = this.termName || Terminal.termName; var name = this.termName || Terminal.termName;
return (name + '')
.indexOf(term) === 0; return (name + '').indexOf(term) === 0;
}; };
}; };

View File

@ -19,41 +19,47 @@ function fixIndent(data){
.split('\n') .split('\n')
.map(function (line){ .map(function (line){
var count = 0; var count = 0;
while (line.charAt(0) === ' ') { while (line.charAt(0) === ' ') {
line = line.slice(1); line = line.slice(1);
count++; count++;
} }
while (count--) { while (count--) {
line = '&nbsp;' + line; line = '&nbsp;' + line;
} }
return line; return line;
}) })
.join('\r\n'); .join('\r\n');
} }
module.exports = function (Terminal){ module.exports = function (Terminal){
Terminal.prototype.bell = function (){ Terminal.prototype.bell = function (){
var snd = new Audio("bell.wav"); // buffers automatically when created var snd = new Audio("bell.wav"); // buffers automatically when created
snd.play(); snd.play();
if (!Terminal.visualBell) return; if (!Terminal.visualBell) return;
var self = this; var self = this;
this.element.style.borderColor = 'white'; this.element.style.borderColor = 'white';
setTimeout(function (){ setTimeout(function (){
self.element.style.borderColor = ''; self.element.style.borderColor = '';
}, 10); }, 10);
if (Terminal.popOnBell) this.focus(); if (Terminal.popOnBell) this.focus();
}; };
Terminal.prototype.write = function (data){ Terminal.prototype.write = function (data){
data = fixLinefeed(data); data = fixLinefeed(data);
data = fixIndent(data); data = fixIndent(data);
var l = data.length, var l = data.length;
i = 0, var i = 0;
cs, ch; var cs, ch;
this.refreshStart = this.y; this.refreshStart = this.y;
this.refreshEnd = this.y; this.refreshEnd = this.y;
@ -63,22 +69,16 @@ module.exports = function (Terminal){
this.maxRange(); this.maxRange();
} }
// this.log(JSON.stringify(data.replace(/\x1b/g, '^[')));
for (; i < l; i++) { for (; i < l; i++) {
ch = data[i]; ch = data[i];
switch (this.state) { switch (this.state) {
case states.normal: case states.normal:
switch (ch) { switch (ch) {
// '\0'
// case '\0':
// break;
// '\a' // '\a'
case '\x07': case '\x07':
this.bell(); this.bell();
break; break;
// '\n', '\v', '\f' // '\n', '\v', '\f'
case '\n': case '\n':
case '\x0b': case '\x0b':
@ -86,47 +86,42 @@ module.exports = function (Terminal){
if (this.convertEol) { if (this.convertEol) {
this.x = 0; this.x = 0;
} }
this.y++; this.y++;
break; break;
// '\r' // '\r'
case '\r': case '\r':
this.x = 0; this.x = 0;
break; break;
// '\b' // '\b'
case '\x08': case '\x08':
if (this.x > 0) { if (this.x > 0) {
this.x--; this.x--;
} }
break; break;
// '\t' // '\t'
case '\t': case '\t':
this.x = this.nextStop(); this.x = this.nextStop();
break; break;
// shift out // shift out
case '\x0e': case '\x0e':
this.setgLevel(1); this.setgLevel(1);
break; break;
// shift in // shift in
case '\x0f': case '\x0f':
this.setgLevel(0); this.setgLevel(0);
break; break;
// '\e' // '\e'
case '\x1b': case '\x1b':
this.state = states.escaped; this.state = states.escaped;
break; break;
default: default:
// ' ' // ' '
if (ch >= ' ') { if (ch >= ' ') {
if (this.charset && this.charset[ch]) { if (this.charset && this.charset[ch]) {
ch = this.charset[ch]; ch = this.charset[ch];
} }
if (this.x >= this.cols) { if (this.x >= this.cols) {
this.x = 0; this.x = 0;
this.y++; this.y++;
@ -150,38 +145,32 @@ module.exports = function (Terminal){
this.currentParam = 0; this.currentParam = 0;
this.state = states.csi; this.state = states.csi;
break; break;
// ESC ] Operating System Command ( OSC is 0x9d). // ESC ] Operating System Command ( OSC is 0x9d).
case ']': case ']':
this.params = []; this.params = [];
this.currentParam = 0; this.currentParam = 0;
this.state = states.osc; this.state = states.osc;
break; break;
// ESC P Device Control String ( DCS is 0x90). // ESC P Device Control String ( DCS is 0x90).
case 'P': case 'P':
this.params = []; this.params = [];
this.currentParam = 0; this.currentParam = 0;
this.state = states.dcs; this.state = states.dcs;
break; break;
// ESC _ Application Program Command ( APC is 0x9f). // ESC _ Application Program Command ( APC is 0x9f).
case '_': case '_':
this.stateType = 'apc'; this.stateType = 'apc';
this.state = states.ignore; this.state = states.ignore;
break; break;
// ESC ^ Privacy Message ( PM is 0x9e). // ESC ^ Privacy Message ( PM is 0x9e).
case '^': case '^':
this.stateType = 'pm'; this.stateType = 'pm';
this.state = states.ignore; this.state = states.ignore;
break; break;
// ESC c Full Reset (RIS). // ESC c Full Reset (RIS).
case 'c': case 'c':
this.reset(); this.reset();
break; break;
// ESC E Next Line ( NEL is 0x85). // ESC E Next Line ( NEL is 0x85).
// ESC D Index ( IND is 0x84). // ESC D Index ( IND is 0x84).
case 'E': case 'E':
@ -190,22 +179,20 @@ module.exports = function (Terminal){
case 'D': case 'D':
this.index(); this.index();
break; break;
// ESC M Reverse Index ( RI is 0x8d). // ESC M Reverse Index ( RI is 0x8d).
case 'M': case 'M':
this.reverseIndex(); this.reverseIndex();
break; break;
// ESC % Select default/utf-8 character set. // ESC % Select default/utf-8 character set.
// @ = default, G = utf-8 // @ = default, G = utf-8
case '%': case '%':
//this.charset = null; //this.charset = null;
this.setgLevel(0); this.setgLevel(0);
this.setgCharset(0, Terminal.charsets.US); this.setgCharset(0, Terminal.charsets.US);
this.state = states.normal; this.state = states.normal;
i++; i++;
break; break;
// ESC (,),*,+,-,. Designate G0-G2 Character Set. // ESC (,),*,+,-,. Designate G0-G2 Character Set.
case '(': case '(':
// <-- this seems to get all the attention // <-- this seems to get all the attention
@ -236,7 +223,6 @@ module.exports = function (Terminal){
} }
this.state = states.charset; this.state = states.charset;
break; break;
// Designate G3 Character Set (VT300). // Designate G3 Character Set (VT300).
// A = ISO Latin-1 Supplemental. // A = ISO Latin-1 Supplemental.
// Not implemented. // Not implemented.
@ -245,7 +231,6 @@ module.exports = function (Terminal){
this.state = states.charset; this.state = states.charset;
i--; i--;
break; break;
// ESC N // ESC N
// Single Shift Select of G2 Character Set // Single Shift Select of G2 Character Set
// ( SS2 is 0x8e). This affects next character only. // ( SS2 is 0x8e). This affects next character only.
@ -281,51 +266,43 @@ module.exports = function (Terminal){
case '~': case '~':
this.setgLevel(1); this.setgLevel(1);
break; break;
// ESC 7 Save Cursor (DECSC). // ESC 7 Save Cursor (DECSC).
case '7': case '7':
this.saveCursor(); this.saveCursor();
this.state = states.normal; this.state = states.normal;
break; break;
// ESC 8 Restore Cursor (DECRC). // ESC 8 Restore Cursor (DECRC).
case '8': case '8':
this.restoreCursor(); this.restoreCursor();
this.state = states.normal; this.state = states.normal;
break; break;
// ESC # 3 DEC line height/width // ESC # 3 DEC line height/width
case '#': case '#':
this.state = states.normal; this.state = states.normal;
i++; i++;
break; break;
// ESC H Tab Set (HTS is 0x88). // ESC H Tab Set (HTS is 0x88).
case 'H': case 'H':
this.tabSet(); this.tabSet();
break; break;
// ESC = Application Keypad (DECPAM). // ESC = Application Keypad (DECPAM).
case '=': case '=':
this.log('Serial port requested application keypad.'); this.log('Serial port requested application keypad.');
this.applicationKeypad = true; this.applicationKeypad = true;
this.state = states.normal; this.state = states.normal;
break; break;
// ESC > Normal Keypad (DECPNM). // ESC > Normal Keypad (DECPNM).
case '>': case '>':
this.log('Switching back to normal keypad.'); this.log('Switching back to normal keypad.');
this.applicationKeypad = false; this.applicationKeypad = false;
this.state = states.normal; this.state = states.normal;
break; break;
default: default:
this.state = states.normal; this.state = states.normal;
this.error('Unknown ESC control: %s.', ch); this.error('Unknown ESC control: %s.', ch);
break; break;
} }
break; break;
case states.charset: case states.charset:
switch (ch) { switch (ch) {
case '0': case '0':
@ -393,11 +370,12 @@ module.exports = function (Terminal){
cs = Terminal.charsets.US; cs = Terminal.charsets.US;
break; break;
} }
this.setgCharset(this.gcharset, cs); this.setgCharset(this.gcharset, cs);
this.gcharset = null; this.gcharset = null;
this.state = states.normal; this.state = states.normal;
break; break;
case states.osc: case states.osc:
// OSC Ps ; Pt ST // OSC Ps ; Pt ST
// OSC Ps ; Pt BEL // OSC Ps ; Pt BEL
@ -418,7 +396,6 @@ module.exports = function (Terminal){
if (this.handleTitle) { if (this.handleTitle) {
this.handleTitle(this.title); this.handleTitle(this.title);
} }
} }
break; break;
case 3: case 3:
@ -483,7 +460,6 @@ module.exports = function (Terminal){
} }
} }
break; break;
case states.csi: case states.csi:
// '?', '>', '!' // '?', '>', '!'
if (ch === '?' || ch === '>' || ch === '!') { if (ch === '?' || ch === '>' || ch === '!') {
@ -517,51 +493,42 @@ module.exports = function (Terminal){
case 'A': case 'A':
this.cursorUp(this.params); this.cursorUp(this.params);
break; break;
// CSI Ps B // CSI Ps B
// Cursor Down Ps Times (default = 1) (CUD). // Cursor Down Ps Times (default = 1) (CUD).
case 'B': case 'B':
this.cursorDown(this.params); this.cursorDown(this.params);
break; break;
// CSI Ps C // CSI Ps C
// Cursor Forward Ps Times (default = 1) (CUF). // Cursor Forward Ps Times (default = 1) (CUF).
case 'C': case 'C':
this.cursorForward(this.params); this.cursorForward(this.params);
break; break;
// CSI Ps D // CSI Ps D
// Cursor Backward Ps Times (default = 1) (CUB). // Cursor Backward Ps Times (default = 1) (CUB).
case 'D': case 'D':
this.cursorBackward(this.params); this.cursorBackward(this.params);
break; break;
// CSI Ps ; Ps H // CSI Ps ; Ps H
// Cursor Position [row;column] (default = [1,1]) (CUP). // Cursor Position [row;column] (default = [1,1]) (CUP).
case 'H': case 'H':
this.cursorPos(this.params); this.cursorPos(this.params);
break; break;
// CSI Ps J Erase in Display (ED). // CSI Ps J Erase in Display (ED).
case 'J': case 'J':
this.eraseInDisplay(this.params); this.eraseInDisplay(this.params);
break; break;
// CSI Ps K Erase in Line (EL). // CSI Ps K Erase in Line (EL).
case 'K': case 'K':
this.eraseInLine(this.params); this.eraseInLine(this.params);
break; break;
// CSI Pm m Character Attributes (SGR). // CSI Pm m Character Attributes (SGR).
case 'm': case 'm':
this.charAttributes(this.params); this.charAttributes(this.params);
break; break;
// CSI Ps n Device Status Report (DSR). // CSI Ps n Device Status Report (DSR).
case 'n': case 'n':
this.deviceStatus(this.params); this.deviceStatus(this.params);
break; break;
/** /**
* Additions * Additions
*/ */
@ -571,61 +538,51 @@ module.exports = function (Terminal){
case '@': case '@':
this.insertChars(this.params); this.insertChars(this.params);
break; break;
// CSI Ps E // CSI Ps E
// Cursor Next Line Ps Times (default = 1) (CNL). // Cursor Next Line Ps Times (default = 1) (CNL).
case 'E': case 'E':
this.cursorNextLine(this.params); this.cursorNextLine(this.params);
break; break;
// CSI Ps F // CSI Ps F
// Cursor Preceding Line Ps Times (default = 1) (CNL). // Cursor Preceding Line Ps Times (default = 1) (CNL).
case 'F': case 'F':
this.cursorPrecedingLine(this.params); this.cursorPrecedingLine(this.params);
break; break;
// CSI Ps G // CSI Ps G
// Cursor Character Absolute [column] (default = [row,1]) (CHA). // Cursor Character Absolute [column] (default = [row,1]) (CHA).
case 'G': case 'G':
this.cursorCharAbsolute(this.params); this.cursorCharAbsolute(this.params);
break; break;
// CSI Ps L // CSI Ps L
// Insert Ps Line(s) (default = 1) (IL). // Insert Ps Line(s) (default = 1) (IL).
case 'L': case 'L':
this.insertLines(this.params); this.insertLines(this.params);
break; break;
// CSI Ps M // CSI Ps M
// Delete Ps Line(s) (default = 1) (DL). // Delete Ps Line(s) (default = 1) (DL).
case 'M': case 'M':
this.deleteLines(this.params); this.deleteLines(this.params);
break; break;
// CSI Ps P // CSI Ps P
// Delete Ps Character(s) (default = 1) (DCH). // Delete Ps Character(s) (default = 1) (DCH).
case 'P': case 'P':
this.deleteChars(this.params); this.deleteChars(this.params);
break; break;
// CSI Ps X // CSI Ps X
// Erase Ps Character(s) (default = 1) (ECH). // Erase Ps Character(s) (default = 1) (ECH).
case 'X': case 'X':
this.eraseChars(this.params); this.eraseChars(this.params);
break; break;
// CSI Pm ` Character Position Absolute // CSI Pm ` Character Position Absolute
// [column] (default = [row,1]) (HPA). // [column] (default = [row,1]) (HPA).
case '`': case '`':
this.charPosAbsolute(this.params); this.charPosAbsolute(this.params);
break; break;
// 141 61 a * HPR - // 141 61 a * HPR -
// Horizontal Position Relative // Horizontal Position Relative
case 'a': case 'a':
this.HPositionRelative(this.params); this.HPositionRelative(this.params);
break; break;
// CSI P s c // CSI P s c
// Send Device Attributes (Primary DA). // Send Device Attributes (Primary DA).
// CSI > P s c // CSI > P s c
@ -633,37 +590,31 @@ module.exports = function (Terminal){
case 'c': case 'c':
//- this.sendDeviceAttributes(this.params); //- this.sendDeviceAttributes(this.params);
break; break;
// CSI Pm d // CSI Pm d
// Line Position Absolute [row] (default = [1,column]) (VPA). // Line Position Absolute [row] (default = [1,column]) (VPA).
case 'd': case 'd':
this.linePosAbsolute(this.params); this.linePosAbsolute(this.params);
break; break;
// 145 65 e * VPR - Vertical Position Relative // 145 65 e * VPR - Vertical Position Relative
case 'e': case 'e':
this.VPositionRelative(this.params); this.VPositionRelative(this.params);
break; break;
// CSI Ps ; Ps f // CSI Ps ; Ps f
// Horizontal and Vertical Position [row;column] (default = // Horizontal and Vertical Position [row;column] (default =
// [1,1]) (HVP). // [1,1]) (HVP).
case 'f': case 'f':
this.HVPosition(this.params); this.HVPosition(this.params);
break; break;
// CSI Pm h Set Mode (SM). // CSI Pm h Set Mode (SM).
// CSI ? Pm h - mouse escape codes, cursor escape codes // CSI ? Pm h - mouse escape codes, cursor escape codes
case 'h': case 'h':
//- this.setMode(this.params); //- this.setMode(this.params);
break; break;
// CSI Pm l Reset Mode (RM). // CSI Pm l Reset Mode (RM).
// CSI ? Pm l // CSI ? Pm l
case 'l': case 'l':
//- this.resetMode(this.params); //- this.resetMode(this.params);
break; break;
// CSI Ps ; Ps r // CSI Ps ; Ps r
// Set Scrolling Region [top;bottom] (default = full size of win- // Set Scrolling Region [top;bottom] (default = full size of win-
// dow) (DECSTBM). // dow) (DECSTBM).
@ -671,19 +622,16 @@ module.exports = function (Terminal){
case 'r': case 'r':
//- this.setScrollRegion(this.params); //- this.setScrollRegion(this.params);
break; break;
// CSI s // CSI s
// Save cursor (ANSI.SYS). // Save cursor (ANSI.SYS).
case 's': case 's':
this.saveCursor(this.params); this.saveCursor(this.params);
break; break;
// CSI u // CSI u
// Restore cursor (ANSI.SYS). // Restore cursor (ANSI.SYS).
case 'u': case 'u':
this.restoreCursor(this.params); this.restoreCursor(this.params);
break; break;
/** /**
* Lesser Used * Lesser Used
*/ */
@ -693,12 +641,10 @@ module.exports = function (Terminal){
case 'I': case 'I':
this.cursorForwardTab(this.params); this.cursorForwardTab(this.params);
break; break;
// CSI Ps S Scroll up Ps lines (default = 1) (SU). // CSI Ps S Scroll up Ps lines (default = 1) (SU).
case 'S': case 'S':
//- this.scrollUp(this.params); //- this.scrollUp(this.params);
break; break;
// CSI Ps T Scroll down Ps lines (default = 1) (SD). // CSI Ps T Scroll down Ps lines (default = 1) (SD).
// CSI Ps ; Ps ; Ps ; Ps ; Ps T // CSI Ps ; Ps ; Ps ; Ps ; Ps T
// CSI > Ps; Ps T // CSI > Ps; Ps T
@ -707,18 +653,15 @@ module.exports = function (Terminal){
//- this.scrollDown(this.params); //- this.scrollDown(this.params);
} }
break; break;
// CSI Ps Z // CSI Ps Z
// Cursor Backward Tabulation Ps tab stops (default = 1) (CBT). // Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
case 'Z': case 'Z':
this.cursorBackwardTab(this.params); this.cursorBackwardTab(this.params);
break; break;
// CSI Ps b Repeat the preceding graphic character Ps times (REP). // CSI Ps b Repeat the preceding graphic character Ps times (REP).
case 'b': case 'b':
this.repeatPrecedingCharacter(this.params); this.repeatPrecedingCharacter(this.params);
break; break;
// CSI Ps g Tab Clear (TBC). // CSI Ps g Tab Clear (TBC).
case 'g': case 'g':
this.tabClear(this.params); this.tabClear(this.params);
@ -730,7 +673,6 @@ module.exports = function (Terminal){
break; break;
} }
break; break;
default: default:
this.error('Unknown CSI code: %s.', ch); this.error('Unknown CSI code: %s.', ch);
break; break;
@ -739,7 +681,6 @@ module.exports = function (Terminal){
this.prefix = ''; this.prefix = '';
this.postfix = ''; this.postfix = '';
break; break;
case states.dcs: case states.dcs:
if (ch === '\x1b' || ch === '\x07') { if (ch === '\x1b' || ch === '\x07') {
if (ch === '\x1b') i++; if (ch === '\x1b') i++;
@ -748,47 +689,37 @@ module.exports = function (Terminal){
// User-Defined Keys (DECUDK). // User-Defined Keys (DECUDK).
case '': case '':
break; break;
// Request Status String (DECRQSS). // Request Status String (DECRQSS).
// test: echo -e '\eP$q"p\e\\' // test: echo -e '\eP$q"p\e\\'
case '$q': case '$q':
var pt = this.currentParam, var pt = this.currentParam,
valid = false; valid = false;
switch (pt) { switch (pt) {
// DECSCA // DECSCA
case '"q': case '"q':
pt = '0"q'; pt = '0"q';
break; break;
// DECSCL // DECSCL
case '"p': case '"p':
pt = '61"p'; pt = '61"p';
break; break;
// DECSTBM // DECSTBM
case 'r': case 'r':
pt = '' + (this.scrollTop + 1) + ';' + (this.scrollBottom + 1) + 'r'; pt = '' + (this.scrollTop + 1) + ';' + (this.scrollBottom + 1) + 'r';
break; break;
// SGR // SGR
case 'm': case 'm':
pt = '0m'; pt = '0m';
break; break;
default: default:
this.error('Unknown DCS Pt: %s.', pt); this.error('Unknown DCS Pt: %s.', pt);
pt = ''; pt = '';
break; break;
} }
//- this.send('\x1bP' + valid + '$r' + pt + '\x1b\\');
break; break;
// Set Termcap/Terminfo Data (xterm, experimental). // Set Termcap/Terminfo Data (xterm, experimental).
case '+p': case '+p':
break; break;
default: default:
this.error('Unknown DCS prefix: %s.', this.prefix); this.error('Unknown DCS prefix: %s.', this.prefix);
break; break;
@ -809,7 +740,6 @@ module.exports = function (Terminal){
this.currentParam += ch; this.currentParam += ch;
} }
break; break;
case states.ignore: case states.ignore:
// For PM and APC. // For PM and APC.
if (ch === '\x1b' || ch === '\x07') { if (ch === '\x1b' || ch === '\x07') {
@ -831,6 +761,7 @@ module.exports = function (Terminal){
Terminal.prototype.writeln = function (data){ Terminal.prototype.writeln = function (data){
// at times spaces appear in between escape chars and fixIndent fails us, so we fix it here // at times spaces appear in between escape chars and fixIndent fails us, so we fix it here
data = data.replace(/ /g, '&nbsp;'); data = data.replace(/ /g, '&nbsp;');
// adding empty char before line break ensures that empty lines render properly // adding empty char before line break ensures that empty lines render properly
this.write(data + ' \r\n'); this.write(data + ' \r\n');
}; };