update files

This commit is contained in:
nuintun 2015-11-26 10:53:50 +08:00
parent f763bf9759
commit ef1690ae5f
12 changed files with 130 additions and 35 deletions

View File

@ -8,6 +8,12 @@ var states = require('./lib/states');
module.exports = Terminal;
/**
* iterator
* @param from
* @param iterator
* @param context
*/
function iterator(from, iterator, context){
for (var key in from) {
if (from.hasOwnProperty(key)) {
@ -16,11 +22,18 @@ function iterator(from, iterator, context){
}
}
/**
* Terminal
* @param options
* @returns {Terminal}
* @constructor
*/
function Terminal(options){
options = options || {};
if (!(this instanceof Terminal)) return new Terminal(options);
// inherits
iterator(Terminal.defaults, function (key, value){
if (options.hasOwnProperty(options)) {
this[key] = options[key];
@ -30,6 +43,7 @@ function Terminal(options){
}
}, this);
// set colors
if (Array.isArray(options.colors)) {
if (options.colors.length === 8) {
options.colors = options.colors.concat(Terminal.colors.slice(8));
@ -46,36 +60,43 @@ function Terminal(options){
options.colors = Terminal.colors;
}
this.cols = options.cols || Terminal.geometry[0];
this.rows = options.rows || Terminal.geometry[1];
this.colors = options.colors;
this.bgColor = options.bgColor || Terminal.defaultColors.bgColor;
this.fgColor = options.fgColor || Terminal.defaultColors.fgColor;
// set screen size
options.cols = options.cols || Terminal.geometry[0];
options.rows = options.rows || Terminal.geometry[1];
this.cols = options.cols;
this.rows = options.rows;
// set handler
options.handler = typeof options.handler === 'function' ? options.handler : function (){};
this.handler = options.handler;
// set handle title
options.handleTitle = typeof options.handleTitle === 'function' ? options.handleTitle : function (){};
this.handleTitle = options.handleTitle;
// set convert eol
options.convertEol = options.convertEol === true;
this.convertEol = options.convertEol;
// set options
this.options = options;
this.ybase = 0;
this.ydisp = 0;
// set property
this.x = 0;
this.y = 0;
this.ybase = 0;
this.ydisp = 0;
this.cursorState = 0;
this.cursorHidden = false;
this.state = states.normal;
this.queue = '';
this.scrollTop = 0;
this.scrollBottom = this.rows - 1;
// modes
// Modes
this.applicationKeypad = false;
this.originMode = false;
this.insertMode = false;
@ -101,24 +122,28 @@ function Terminal(options){
this.readable = true;
this.writable = true;
// set attr
this.defAttr = (257 << 9) | 256;
this.curAttr = this.defAttr;
// set params
this.params = [];
this.currentParam = 0;
this.prefix = '';
this.postfix = '';
// set lines
this.lines = [];
// set tabs
this.tabs = null;
var i = this.rows;
while (i--) {
this.lines.push(this.blankLine());
}
this.tabs = null;
this.setupStops();
}

View File

@ -5,6 +5,11 @@
'use strict';
module.exports = function (Terminal){
/**
* blankLine
* @param cur
* @returns {Array}
*/
Terminal.prototype.blankLine = function (cur){
var attr = cur ? this.eraseAttr() : this.defAttr;
var ch = [attr, ' '];

View File

@ -48,7 +48,7 @@ module.exports = function (Terminal){
'}': '\u00a3', // '£'
'~': '\u00b7' // '·'
};
Terminal.charsets.UK = null; // (A
Terminal.charsets.US = null; // (B (USASCII)
Terminal.charsets.Dutch = null; // (4

View File

@ -5,6 +5,9 @@
'use strict';
module.exports = function (Terminal){
/**
* close
*/
Terminal.prototype.close = function (){
this.lines = [];
this.children = [];

View File

@ -5,6 +5,13 @@
'use strict';
module.exports = function (Terminal){
/**
* matchColor
* @param r1
* @param g1
* @param b1
* @returns {*}
*/
function matchColor(r1, g1, b1){
var hash = (r1 << 16) | (g1 << 8) | b1;

View File

@ -189,7 +189,9 @@ module.exports = function (Terminal){
break;
// show cursor
case 25:
this.cursorHidden = false;
this.cursor = true;
this.showCursor();
break;
// alt screen buffer cursor
case 1049:
@ -382,7 +384,9 @@ module.exports = function (Terminal){
break;
// hide cursor
case 25:
this.cursorHidden = true;
this.cursor = false;
this.hideCursor();
break;
// alt screen buffer cursor
case 1049:

View File

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

View File

@ -5,38 +5,73 @@
'use strict';
module.exports = function (Terminal){
Terminal.prototype.blinkCursor = function (){
if (Terminal.focus !== this) return;
this.cursorState ^= 1;
this.refresh(this.y, this.y);
};
/**
* showCursor
*/
Terminal.prototype.showCursor = function (){
if (!this.cursorState) {
if (this.cursor) {
this._cursor = true;
this.cursorState = 1;
this.refresh(this.y, this.y);
}
};
Terminal.prototype.startBlink = function (){
if (!this.cursorBlink) return;
/**
* hideCursor
*/
Terminal.prototype.hideCursor = function (){
if (this._cursor) {
delete this._cursor;
var context = this;
this.cursorState = 0;
this._blinker = function (){
context.blinkCursor();
};
if (this._blink && this._blinker) {
clearInterval(this._blink);
this._blink = setInterval(this._blinker, 500);
delete this._blink;
delete this._blinker;
}
this.refresh(this.y, this.y);
}
};
Terminal.prototype.refreshBlink = function (){
if (!this.cursorBlink) return;
/**
* startBlink
*/
Terminal.prototype.startBlink = function (){
if (this.cursor && this.cursorBlink && Terminal.focus === this) {
var context = this;
clearInterval(this._blink);
this.stopBlink();
this._blinker = function (){
context.cursorState ^= 1;
this._blink = setInterval(this._blinker, 500);
context.refresh(this.y, this.y);
};
this._blink = setInterval(this._blinker, this.cursorBlinkSpeed);
}
};
/**
* stopBlink
*/
Terminal.prototype.stopBlink = function (){
if (this._blink && this._blinker) {
clearInterval(this._blink);
delete this._blink;
delete this._blinker;
if (this.cursor && this._cursor) {
this.cursorState = 1;
} else {
this.cursorState = 0;
}
this.refresh(this.y, this.y);
}
};
};

View File

@ -22,8 +22,7 @@ module.exports = function (Terminal){
Terminal.prototype.blur = function (){
if (Terminal.focus !== this) return;
this.cursorState = 0;
this.refresh(this.y, this.y);
this.hideCursor();
Terminal.focus = null;
};

View File

@ -8,7 +8,9 @@ module.exports = function (Terminal){
Terminal.termName = 'xterm';
Terminal.debug = false;
Terminal.geometry = [100, 80];
Terminal.cursor = true;
Terminal.cursorBlink = true;
Terminal.cursorBlinkSpeed = 500;
Terminal.visualBell = true;
Terminal.popOnBell = true;
Terminal.scrollback = 640;
@ -19,7 +21,9 @@ module.exports = function (Terminal){
Terminal.defaults = {
debug: Terminal.debug,
termName: Terminal.termName,
cursor: Terminal.cursor,
cursorBlink: Terminal.cursorBlink,
cursorBlinkSpeed: Terminal.cursorBlinkSpeed,
visualBell: Terminal.visualBell,
popOnBell: Terminal.popOnBell,
scrollback: Terminal.scrollback,

View File

@ -40,7 +40,7 @@ module.exports = function (Terminal){
row = y + this.ydisp;
line = this.lines[row];
if (y === this.y && this.cursorState && this.ydisp === this.ybase && !this.cursorHidden) {
if (y === this.y && this.cursor && this.cursorState && this.ydisp === this.ybase) {
x = this.x;
} else {
x = -1;

View File

@ -6,6 +6,10 @@
// ignore warnings regarging == and != (coersion makes things work here appearently)
module.exports = function (Terminal){
/**
* setupStops
* @param i
*/
Terminal.prototype.setupStops = function (i){
if (arguments.length) {
if (!this.tabs[i]) {
@ -21,6 +25,11 @@ module.exports = function (Terminal){
}
};
/**
* prevStop
* @param x
* @returns {number}
*/
Terminal.prototype.prevStop = function (x){
if (!arguments.length) x = this.x;
@ -29,6 +38,11 @@ module.exports = function (Terminal){
return x >= this.cols ? this.cols - 1 : x < 0 ? 0 : x;
};
/**
* nextStop
* @param x
* @returns {number}
*/
Terminal.prototype.nextStop = function (x){
if (!arguments.length) x = this.x;