mirror of
https://github.com/nuintun/command-manager.git
synced 2025-06-08 20:24:04 +08:00
update files
This commit is contained in:
parent
f763bf9759
commit
ef1690ae5f
@ -8,6 +8,12 @@ var states = require('./lib/states');
|
|||||||
|
|
||||||
module.exports = Terminal;
|
module.exports = Terminal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* iterator
|
||||||
|
* @param from
|
||||||
|
* @param iterator
|
||||||
|
* @param context
|
||||||
|
*/
|
||||||
function iterator(from, iterator, context){
|
function iterator(from, iterator, context){
|
||||||
for (var key in from) {
|
for (var key in from) {
|
||||||
if (from.hasOwnProperty(key)) {
|
if (from.hasOwnProperty(key)) {
|
||||||
@ -16,11 +22,18 @@ function iterator(from, iterator, context){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Terminal
|
||||||
|
* @param options
|
||||||
|
* @returns {Terminal}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
function Terminal(options){
|
function Terminal(options){
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
if (!(this instanceof Terminal)) return new Terminal(options);
|
if (!(this instanceof Terminal)) return new Terminal(options);
|
||||||
|
|
||||||
|
// inherits
|
||||||
iterator(Terminal.defaults, function (key, value){
|
iterator(Terminal.defaults, function (key, value){
|
||||||
if (options.hasOwnProperty(options)) {
|
if (options.hasOwnProperty(options)) {
|
||||||
this[key] = options[key];
|
this[key] = options[key];
|
||||||
@ -30,6 +43,7 @@ function Terminal(options){
|
|||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
|
// set colors
|
||||||
if (Array.isArray(options.colors)) {
|
if (Array.isArray(options.colors)) {
|
||||||
if (options.colors.length === 8) {
|
if (options.colors.length === 8) {
|
||||||
options.colors = options.colors.concat(Terminal.colors.slice(8));
|
options.colors = options.colors.concat(Terminal.colors.slice(8));
|
||||||
@ -46,36 +60,43 @@ function Terminal(options){
|
|||||||
options.colors = Terminal.colors;
|
options.colors = Terminal.colors;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.cols = options.cols || Terminal.geometry[0];
|
|
||||||
this.rows = options.rows || Terminal.geometry[1];
|
|
||||||
|
|
||||||
this.colors = options.colors;
|
this.colors = options.colors;
|
||||||
this.bgColor = options.bgColor || Terminal.defaultColors.bgColor;
|
this.bgColor = options.bgColor || Terminal.defaultColors.bgColor;
|
||||||
this.fgColor = options.fgColor || Terminal.defaultColors.fgColor;
|
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 (){};
|
options.handler = typeof options.handler === 'function' ? options.handler : function (){};
|
||||||
this.handler = options.handler;
|
this.handler = options.handler;
|
||||||
|
|
||||||
|
// set handle title
|
||||||
options.handleTitle = typeof options.handleTitle === 'function' ? options.handleTitle : function (){};
|
options.handleTitle = typeof options.handleTitle === 'function' ? options.handleTitle : function (){};
|
||||||
this.handleTitle = options.handleTitle;
|
this.handleTitle = options.handleTitle;
|
||||||
|
|
||||||
|
// set convert eol
|
||||||
options.convertEol = options.convertEol === true;
|
options.convertEol = options.convertEol === true;
|
||||||
this.convertEol = options.convertEol;
|
this.convertEol = options.convertEol;
|
||||||
|
|
||||||
|
// set options
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
|
||||||
this.ybase = 0;
|
// set property
|
||||||
this.ydisp = 0;
|
|
||||||
this.x = 0;
|
this.x = 0;
|
||||||
this.y = 0;
|
this.y = 0;
|
||||||
|
this.ybase = 0;
|
||||||
|
this.ydisp = 0;
|
||||||
this.cursorState = 0;
|
this.cursorState = 0;
|
||||||
this.cursorHidden = false;
|
|
||||||
this.state = states.normal;
|
this.state = states.normal;
|
||||||
this.queue = '';
|
this.queue = '';
|
||||||
this.scrollTop = 0;
|
this.scrollTop = 0;
|
||||||
this.scrollBottom = this.rows - 1;
|
this.scrollBottom = this.rows - 1;
|
||||||
|
|
||||||
// modes
|
// Modes
|
||||||
this.applicationKeypad = false;
|
this.applicationKeypad = false;
|
||||||
this.originMode = false;
|
this.originMode = false;
|
||||||
this.insertMode = false;
|
this.insertMode = false;
|
||||||
@ -101,24 +122,28 @@ function Terminal(options){
|
|||||||
this.readable = true;
|
this.readable = true;
|
||||||
this.writable = true;
|
this.writable = true;
|
||||||
|
|
||||||
|
// set attr
|
||||||
this.defAttr = (257 << 9) | 256;
|
this.defAttr = (257 << 9) | 256;
|
||||||
this.curAttr = this.defAttr;
|
this.curAttr = this.defAttr;
|
||||||
|
|
||||||
|
// set params
|
||||||
this.params = [];
|
this.params = [];
|
||||||
this.currentParam = 0;
|
this.currentParam = 0;
|
||||||
this.prefix = '';
|
this.prefix = '';
|
||||||
this.postfix = '';
|
this.postfix = '';
|
||||||
|
|
||||||
|
// set lines
|
||||||
this.lines = [];
|
this.lines = [];
|
||||||
|
|
||||||
|
// set tabs
|
||||||
|
this.tabs = null;
|
||||||
|
|
||||||
var i = this.rows;
|
var i = this.rows;
|
||||||
|
|
||||||
while (i--) {
|
while (i--) {
|
||||||
this.lines.push(this.blankLine());
|
this.lines.push(this.blankLine());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.tabs = null;
|
|
||||||
|
|
||||||
this.setupStops();
|
this.setupStops();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = function (Terminal){
|
module.exports = function (Terminal){
|
||||||
|
/**
|
||||||
|
* blankLine
|
||||||
|
* @param cur
|
||||||
|
* @returns {Array}
|
||||||
|
*/
|
||||||
Terminal.prototype.blankLine = function (cur){
|
Terminal.prototype.blankLine = function (cur){
|
||||||
var attr = cur ? this.eraseAttr() : this.defAttr;
|
var attr = cur ? this.eraseAttr() : this.defAttr;
|
||||||
var ch = [attr, ' '];
|
var ch = [attr, ' '];
|
||||||
|
@ -5,6 +5,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = function (Terminal){
|
module.exports = function (Terminal){
|
||||||
|
/**
|
||||||
|
* close
|
||||||
|
*/
|
||||||
Terminal.prototype.close = function (){
|
Terminal.prototype.close = function (){
|
||||||
this.lines = [];
|
this.lines = [];
|
||||||
this.children = [];
|
this.children = [];
|
||||||
|
@ -5,6 +5,13 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = function (Terminal){
|
module.exports = function (Terminal){
|
||||||
|
/**
|
||||||
|
* matchColor
|
||||||
|
* @param r1
|
||||||
|
* @param g1
|
||||||
|
* @param b1
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
function matchColor(r1, g1, b1){
|
function matchColor(r1, g1, b1){
|
||||||
var hash = (r1 << 16) | (g1 << 8) | b1;
|
var hash = (r1 << 16) | (g1 << 8) | b1;
|
||||||
|
|
||||||
|
@ -189,7 +189,9 @@ module.exports = function (Terminal){
|
|||||||
break;
|
break;
|
||||||
// show cursor
|
// show cursor
|
||||||
case 25:
|
case 25:
|
||||||
this.cursorHidden = false;
|
this.cursor = true;
|
||||||
|
|
||||||
|
this.showCursor();
|
||||||
break;
|
break;
|
||||||
// alt screen buffer cursor
|
// alt screen buffer cursor
|
||||||
case 1049:
|
case 1049:
|
||||||
@ -382,7 +384,9 @@ module.exports = function (Terminal){
|
|||||||
break;
|
break;
|
||||||
// hide cursor
|
// hide cursor
|
||||||
case 25:
|
case 25:
|
||||||
this.cursorHidden = true;
|
this.cursor = false;
|
||||||
|
|
||||||
|
this.hideCursor();
|
||||||
break;
|
break;
|
||||||
// alt screen buffer cursor
|
// alt screen buffer cursor
|
||||||
case 1049:
|
case 1049:
|
||||||
|
@ -8,7 +8,6 @@ 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 (){
|
Terminal.prototype.softReset = function (){
|
||||||
this.cursorHidden = false;
|
|
||||||
this.insertMode = false;
|
this.insertMode = false;
|
||||||
this.originMode = false;
|
this.originMode = false;
|
||||||
// autowrap
|
// autowrap
|
||||||
|
@ -5,38 +5,73 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = function (Terminal){
|
module.exports = function (Terminal){
|
||||||
Terminal.prototype.blinkCursor = function (){
|
/**
|
||||||
if (Terminal.focus !== this) return;
|
* showCursor
|
||||||
|
*/
|
||||||
this.cursorState ^= 1;
|
|
||||||
this.refresh(this.y, this.y);
|
|
||||||
};
|
|
||||||
|
|
||||||
Terminal.prototype.showCursor = function (){
|
Terminal.prototype.showCursor = function (){
|
||||||
if (!this.cursorState) {
|
if (this.cursor) {
|
||||||
|
this._cursor = true;
|
||||||
this.cursorState = 1;
|
this.cursorState = 1;
|
||||||
|
|
||||||
this.refresh(this.y, this.y);
|
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 (){
|
if (this._blink && this._blinker) {
|
||||||
context.blinkCursor();
|
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);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -22,8 +22,7 @@ module.exports = function (Terminal){
|
|||||||
Terminal.prototype.blur = function (){
|
Terminal.prototype.blur = function (){
|
||||||
if (Terminal.focus !== this) return;
|
if (Terminal.focus !== this) return;
|
||||||
|
|
||||||
this.cursorState = 0;
|
this.hideCursor();
|
||||||
this.refresh(this.y, this.y);
|
|
||||||
|
|
||||||
Terminal.focus = null;
|
Terminal.focus = null;
|
||||||
};
|
};
|
||||||
|
@ -8,7 +8,9 @@ module.exports = function (Terminal){
|
|||||||
Terminal.termName = 'xterm';
|
Terminal.termName = 'xterm';
|
||||||
Terminal.debug = false;
|
Terminal.debug = false;
|
||||||
Terminal.geometry = [100, 80];
|
Terminal.geometry = [100, 80];
|
||||||
|
Terminal.cursor = true;
|
||||||
Terminal.cursorBlink = true;
|
Terminal.cursorBlink = true;
|
||||||
|
Terminal.cursorBlinkSpeed = 500;
|
||||||
Terminal.visualBell = true;
|
Terminal.visualBell = true;
|
||||||
Terminal.popOnBell = true;
|
Terminal.popOnBell = true;
|
||||||
Terminal.scrollback = 640;
|
Terminal.scrollback = 640;
|
||||||
@ -19,7 +21,9 @@ module.exports = function (Terminal){
|
|||||||
Terminal.defaults = {
|
Terminal.defaults = {
|
||||||
debug: Terminal.debug,
|
debug: Terminal.debug,
|
||||||
termName: Terminal.termName,
|
termName: Terminal.termName,
|
||||||
|
cursor: Terminal.cursor,
|
||||||
cursorBlink: Terminal.cursorBlink,
|
cursorBlink: Terminal.cursorBlink,
|
||||||
|
cursorBlinkSpeed: Terminal.cursorBlinkSpeed,
|
||||||
visualBell: Terminal.visualBell,
|
visualBell: Terminal.visualBell,
|
||||||
popOnBell: Terminal.popOnBell,
|
popOnBell: Terminal.popOnBell,
|
||||||
scrollback: Terminal.scrollback,
|
scrollback: Terminal.scrollback,
|
||||||
|
@ -40,7 +40,7 @@ module.exports = function (Terminal){
|
|||||||
row = y + this.ydisp;
|
row = y + this.ydisp;
|
||||||
line = this.lines[row];
|
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;
|
x = this.x;
|
||||||
} else {
|
} else {
|
||||||
x = -1;
|
x = -1;
|
||||||
|
@ -6,6 +6,10 @@
|
|||||||
|
|
||||||
// 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){
|
||||||
|
/**
|
||||||
|
* setupStops
|
||||||
|
* @param i
|
||||||
|
*/
|
||||||
Terminal.prototype.setupStops = function (i){
|
Terminal.prototype.setupStops = function (i){
|
||||||
if (arguments.length) {
|
if (arguments.length) {
|
||||||
if (!this.tabs[i]) {
|
if (!this.tabs[i]) {
|
||||||
@ -21,6 +25,11 @@ module.exports = function (Terminal){
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* prevStop
|
||||||
|
* @param x
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
Terminal.prototype.prevStop = function (x){
|
Terminal.prototype.prevStop = function (x){
|
||||||
if (!arguments.length) x = this.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;
|
return x >= this.cols ? this.cols - 1 : x < 0 ? 0 : x;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* nextStop
|
||||||
|
* @param x
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
Terminal.prototype.nextStop = function (x){
|
Terminal.prototype.nextStop = function (x){
|
||||||
if (!arguments.length) x = this.x;
|
if (!arguments.length) x = this.x;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user