update files

This commit is contained in:
nuintun 2015-11-26 11:45:31 +08:00
parent 93b8d9342b
commit 8d2af4a433
14 changed files with 178 additions and 82 deletions

View File

@ -180,6 +180,7 @@ require('./lib/esc/tabSet.js')(Terminal);
require('./lib/charsets.js')(Terminal); require('./lib/charsets.js')(Terminal);
require('./lib/csi/charAttributes')(Terminal); require('./lib/csi/charAttributes')(Terminal);
require('./lib/csi/erase')(Terminal);
require('./lib/csi/insert-delete')(Terminal); require('./lib/csi/insert-delete')(Terminal);
require('./lib/csi/position')(Terminal); require('./lib/csi/position')(Terminal);
require('./lib/csi/cursor')(Terminal); require('./lib/csi/cursor')(Terminal);

View File

@ -0,0 +1,73 @@
/**
* Created by nuintun on 2015/11/24.
*/
'use strict';
module.exports = function (Terminal){
// CSI Ps J Erase in Display (ED).
// Ps = 0 -> Erase Below (default).
// Ps = 1 -> Erase Above.
// Ps = 2 -> Erase All.
// Ps = 3 -> Erase Saved Lines (xterm).
// CSI ? Ps J
// Erase in Display (DECSED).
// Ps = 0 -> Selective Erase Below (default).
// Ps = 1 -> Selective Erase Above.
// Ps = 2 -> Selective Erase All.
Terminal.prototype.eraseInDisplay = function (params){
var j;
switch (params[0]) {
case 0:
this.eraseRight(this.x, this.y);
j = this.y + 1;
for (; j < this.rows; j++) {
this.eraseLine(j);
}
break;
case 1:
this.eraseLeft(this.x, this.y);
j = this.y;
while (j--) {
this.eraseLine(j);
}
break;
case 2:
j = this.rows;
while (j--) this.eraseLine(j);
break;
case 3:
// no saved lines
break;
}
};
// CSI Ps K Erase in Line (EL).
// Ps = 0 -> Erase to Right (default).
// Ps = 1 -> Erase to Left.
// Ps = 2 -> Erase All.
// CSI ? Ps K
// Erase in Line (DECSEL).
// Ps = 0 -> Selective Erase to Right (default).
// Ps = 1 -> Selective Erase to Left.
// Ps = 2 -> Selective Erase All.
Terminal.prototype.eraseInLine = function (params){
switch (params[0]) {
case 0:
this.eraseRight(this.x, this.y);
break;
case 1:
this.eraseLeft(this.x, this.y);
break;
case 2:
this.eraseLine(this.y);
break;
}
};
};

View File

@ -5,6 +5,9 @@
'use strict'; 'use strict';
module.exports = function (Terminal){ module.exports = function (Terminal){
/**
* log
*/
Terminal.prototype.log = function (){ Terminal.prototype.log = function (){
if (!this.debug) return; if (!this.debug) return;
@ -15,6 +18,9 @@ module.exports = function (Terminal){
window.console.log.apply(window.console, args); window.console.log.apply(window.console, args);
}; };
/**
* error
*/
Terminal.prototype.error = function (){ Terminal.prototype.error = function (){
if (!this.debug) return; if (!this.debug) return;

View File

@ -5,10 +5,19 @@
'use strict'; 'use strict';
module.exports = function (Terminal){ module.exports = function (Terminal){
/**
* eraseAttr
* @returns {number}
*/
Terminal.prototype.eraseAttr = function (){ Terminal.prototype.eraseAttr = function (){
return (this.defAttr & ~0x1ff) | (this.curAttr & 0x1ff); return (this.defAttr & ~0x1ff) | (this.curAttr & 0x1ff);
}; };
/**
* eraseRight
* @param x
* @param y
*/
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];
var ch = [this.eraseAttr(), ' ']; var ch = [this.eraseAttr(), ' '];
@ -20,6 +29,11 @@ module.exports = function (Terminal){
this.updateRange(y); this.updateRange(y);
}; };
/**
* eraseLeft
* @param x
* @param y
*/
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];
var ch = [this.eraseAttr(), ' ']; var ch = [this.eraseAttr(), ' '];
@ -31,73 +45,11 @@ module.exports = function (Terminal){
this.updateRange(y); this.updateRange(y);
}; };
/**
* eraseLine
* @param y
*/
Terminal.prototype.eraseLine = function (y){ Terminal.prototype.eraseLine = function (y){
this.eraseRight(0, y); this.eraseRight(0, y);
}; };
// CSI Ps J Erase in Display (ED).
// Ps = 0 -> Erase Below (default).
// Ps = 1 -> Erase Above.
// Ps = 2 -> Erase All.
// Ps = 3 -> Erase Saved Lines (xterm).
// CSI ? Ps J
// Erase in Display (DECSED).
// Ps = 0 -> Selective Erase Below (default).
// Ps = 1 -> Selective Erase Above.
// Ps = 2 -> Selective Erase All.
Terminal.prototype.eraseInDisplay = function (params){
var j;
switch (params[0]) {
case 0:
this.eraseRight(this.x, this.y);
j = this.y + 1;
for (; j < this.rows; j++) {
this.eraseLine(j);
}
break;
case 1:
this.eraseLeft(this.x, this.y);
j = this.y;
while (j--) {
this.eraseLine(j);
}
break;
case 2:
j = this.rows;
while (j--) this.eraseLine(j);
break;
case 3:
// no saved lines
break;
}
};
// CSI Ps K Erase in Line (EL).
// Ps = 0 -> Erase to Right (default).
// Ps = 1 -> Erase to Left.
// Ps = 2 -> Erase All.
// CSI ? Ps K
// Erase in Line (DECSEL).
// Ps = 0 -> Selective Erase to Right (default).
// Ps = 1 -> Selective Erase to Left.
// Ps = 2 -> Selective Erase All.
Terminal.prototype.eraseInLine = function (params){
switch (params[0]) {
case 0:
this.eraseRight(this.x, this.y);
break;
case 1:
this.eraseLeft(this.x, this.y);
break;
case 2:
this.eraseLine(this.y);
break;
}
};
}; };

View File

@ -7,6 +7,9 @@
module.exports = function (Terminal){ module.exports = function (Terminal){
Terminal.focus = null; Terminal.focus = null;
/**
* focus
*/
Terminal.prototype.focus = function (){ Terminal.prototype.focus = function (){
if (Terminal.focus === this) return; if (Terminal.focus === this) return;
@ -25,6 +28,9 @@ module.exports = function (Terminal){
Terminal.focus = this; Terminal.focus = this;
}; };
/**
* blur
*/
Terminal.prototype.blur = function (){ Terminal.prototype.blur = function (){
if (Terminal.focus !== this) return; if (Terminal.focus !== this) return;

View File

@ -26,7 +26,7 @@ function isBoldBroken(){
module.exports = function (Terminal){ module.exports = function (Terminal){
/** /**
* Open Terminal * open
*/ */
Terminal.prototype.open = function (){ Terminal.prototype.open = function (){
var div; var div;

View File

@ -5,12 +5,19 @@
'use strict'; 'use strict';
module.exports = function (Terminal){ module.exports = function (Terminal){
/**
* updateRange
* @param y
*/
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;
}; };
/**
* maxRange
*/
Terminal.prototype.maxRange = function (){ Terminal.prototype.maxRange = function (){
this.refreshStart = 0; this.refreshStart = 0;
this.refreshEnd = this.rows - 1; this.refreshEnd = this.rows - 1;

View File

@ -5,19 +5,22 @@
'use strict'; 'use strict';
module.exports = function (Terminal){ module.exports = function (Terminal){
/** // Rendering Engine
* Rendering Engine // In the screen buffer, each character
*/ // is stored as a an array with a character
// and a 32-bit integer.
// First value: a utf-16 character.
// Second value:
// Next 9 bits: background color (0-511).
// Next 9 bits: foreground color (0-511).
// Next 14 bits: a mask for misc.
// flags: 1=bold, 2=underline, 4=blink, 8=inverse, 16=invisible
// In the screen buffer, each character /**
// is stored as a an array with a character * refresh
// and a 32-bit integer. * @param start
// First value: a utf-16 character. * @param end
// Second value: */
// Next 9 bits: background color (0-511).
// Next 9 bits: foreground color (0-511).
// Next 14 bits: a mask for misc.
// flags: 1=bold, 2=underline, 4=blink, 8=inverse, 16=invisible
Terminal.prototype.refresh = function (start, end){ Terminal.prototype.refresh = function (start, end){
var parent = this.element.parentNode; var parent = this.element.parentNode;
var x, y, i, line, out, ch, width, data, attr, fgColor, bgColor, flags, row; var x, y, i, line, out, ch, width, data, attr, fgColor, bgColor, flags, row;

View File

@ -5,6 +5,11 @@
'use strict'; 'use strict';
module.exports = function (Terminal){ module.exports = function (Terminal){
/**
* resize
* @param x
* @param y
*/
Terminal.prototype.resize = function (x, y){ Terminal.prototype.resize = function (x, y){
var line, element, i, j, ch; var line, element, i, j, ch;

View File

@ -5,6 +5,9 @@
'use strict'; 'use strict';
module.exports = function (Terminal){ module.exports = function (Terminal){
/**
* scroll
*/
Terminal.prototype.scroll = function (){ Terminal.prototype.scroll = function (){
var row; var row;
@ -45,6 +48,10 @@ module.exports = function (Terminal){
this.updateRange(this.scrollBottom); this.updateRange(this.scrollBottom);
}; };
/**
* scrollDisp
* @param disp
*/
Terminal.prototype.scrollDisp = function (disp){ Terminal.prototype.scrollDisp = function (disp){
this.ydisp += disp; this.ydisp += disp;

View File

@ -5,6 +5,11 @@
'use strict'; 'use strict';
module.exports = function (Terminal){ module.exports = function (Terminal){
/**
* setgCharset
* @param g
* @param charset
*/
Terminal.prototype.setgCharset = function (g, charset){ Terminal.prototype.setgCharset = function (g, charset){
this.charsets[g] = charset; this.charsets[g] = charset;

View File

@ -5,6 +5,10 @@
'use strict'; 'use strict';
module.exports = function (Terminal){ module.exports = function (Terminal){
/**
* setgLevel
* @param g
*/
Terminal.prototype.setgLevel = function (g){ Terminal.prototype.setgLevel = function (g){
this.glevel = g; this.glevel = g;
this.charset = this.charsets[g]; this.charset = this.charsets[g];

View File

@ -5,6 +5,11 @@
'use strict'; 'use strict';
module.exports = function (Terminal){ module.exports = function (Terminal){
/**
* isWide
* @param ch
* @returns {boolean}
*/
Terminal.prototype.isWide = function isWide(ch){ Terminal.prototype.isWide = function isWide(ch){
if (ch <= '\uff00') return false; if (ch <= '\uff00') return false;
@ -17,10 +22,20 @@ module.exports = function (Terminal){
|| (ch >= '\uffe8' && ch <= '\uffee'); || (ch >= '\uffe8' && ch <= '\uffee');
}; };
/**
* ch
* @param cur
* @returns {string[]}
*/
Terminal.prototype.ch = function (cur){ Terminal.prototype.ch = function (cur){
return cur ? [this.eraseAttr(), ' '] : [this.defAttr, ' ']; return cur ? [this.eraseAttr(), ' '] : [this.defAttr, ' '];
}; };
/**
* is
* @param term
* @returns {boolean}
*/
Terminal.prototype.is = function (term){ Terminal.prototype.is = function (term){
var name = this.termName; var name = this.termName;

View File

@ -7,6 +7,10 @@
var states = require('./states'); var states = require('./states');
module.exports = function (Terminal){ module.exports = function (Terminal){
/**
* send
* @param data
*/
Terminal.prototype.send = function (data){ Terminal.prototype.send = function (data){
var context = this; var context = this;
@ -21,8 +25,12 @@ module.exports = function (Terminal){
this.queue += data; this.queue += data;
}; };
/**
* bell
*/
Terminal.prototype.bell = function (){ Terminal.prototype.bell = function (){
var snd = new Audio('bell.wav'); // buffers automatically when created // buffers automatically when created
var snd = new Audio('bell.wav');
snd.play(); snd.play();
@ -39,6 +47,10 @@ module.exports = function (Terminal){
if (this.popOnBell) this.focus(); if (this.popOnBell) this.focus();
}; };
/**
* write
* @param data
*/
Terminal.prototype.write = function (data){ Terminal.prototype.write = function (data){
var l = data.length; var l = data.length;
var i = 0; var i = 0;