mirror of
https://github.com/nuintun/command-manager.git
synced 2025-06-07 11:34:05 +08:00
update files
This commit is contained in:
parent
65e67f90da
commit
4e16de9f77
@ -70,19 +70,15 @@ function Terminal(options){
|
|||||||
this.cols = options.cols;
|
this.cols = options.cols;
|
||||||
this.rows = options.rows;
|
this.rows = options.rows;
|
||||||
|
|
||||||
// set ondata
|
// set on data callback
|
||||||
options.ondata = typeof options.ondata === 'function' ? options.ondata : function (){};
|
options.ondata = typeof options.ondata === 'function' ? options.ondata : function (){};
|
||||||
this.ondata = options.ondata;
|
this.ondata = options.ondata;
|
||||||
|
|
||||||
// set ontitle
|
// set on title callback
|
||||||
options.ontitle = typeof options.ontitle === 'function' ? options.ontitle : function (){};
|
options.ontitle = typeof options.ontitle === 'function' ? options.ontitle : function (){};
|
||||||
this.ontitle = options.ontitle;
|
this.ontitle = options.ontitle;
|
||||||
|
|
||||||
// set onscreen
|
// set convert end of line
|
||||||
options.onscreen = typeof options.onscreen === 'function' ? options.onscreen : function (){};
|
|
||||||
this.onscreen = options.onscreen;
|
|
||||||
|
|
||||||
// set convert eol
|
|
||||||
options.convertEOL = options.convertEOL === true;
|
options.convertEOL = options.convertEOL === true;
|
||||||
this.convertEOL = options.convertEOL;
|
this.convertEOL = options.convertEOL;
|
||||||
|
|
||||||
@ -114,8 +110,8 @@ function Terminal(options){
|
|||||||
this.charsets = [null];
|
this.charsets = [null];
|
||||||
|
|
||||||
// misc
|
// misc
|
||||||
this.screen = '';
|
this.element = null;
|
||||||
this.screenLines = [];
|
this.children = [];
|
||||||
this.refreshStart = null;
|
this.refreshStart = null;
|
||||||
this.refreshEnd = null;
|
this.refreshEnd = null;
|
||||||
this.savedX = null;
|
this.savedX = null;
|
||||||
|
@ -10,13 +10,21 @@ module.exports = function (Terminal){
|
|||||||
*/
|
*/
|
||||||
Terminal.prototype.close = function (){
|
Terminal.prototype.close = function (){
|
||||||
this.lines = [];
|
this.lines = [];
|
||||||
this.screen = '';
|
this.children = [];
|
||||||
this.screenLines = [];
|
|
||||||
this.readable = false;
|
this.readable = false;
|
||||||
this.writable = false;
|
this.writable = false;
|
||||||
this.write = function (){};
|
this.write = function (){};
|
||||||
this.ondata = function (){};
|
this.ondata = function (){};
|
||||||
this.ontitle = function (){};
|
this.ondataTitle = function (){};
|
||||||
this.onscreen = function (){};
|
|
||||||
|
if (this.element) {
|
||||||
|
var parent = this.element.parentNode;
|
||||||
|
|
||||||
|
if (parent) {
|
||||||
|
parent.removeChild(this.element);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.element = null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -107,7 +107,7 @@ module.exports = function (Terminal){
|
|||||||
this.insertMode = true;
|
this.insertMode = true;
|
||||||
break;
|
break;
|
||||||
case 20:
|
case 20:
|
||||||
this.convertEol = true;
|
this.convertEOL = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (this.prefix === '?') {
|
} else if (this.prefix === '?') {
|
||||||
@ -322,7 +322,7 @@ module.exports = function (Terminal){
|
|||||||
this.insertMode = false;
|
this.insertMode = false;
|
||||||
break;
|
break;
|
||||||
case 20:
|
case 20:
|
||||||
this.convertEol = false;
|
this.convertEOL = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (this.prefix === '?') {
|
} else if (this.prefix === '?') {
|
||||||
|
@ -7,14 +7,6 @@
|
|||||||
module.exports = function (Terminal){
|
module.exports = function (Terminal){
|
||||||
Terminal.focus = null;
|
Terminal.focus = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* isFocused
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
Terminal.prototype.isFocused = function (){
|
|
||||||
return Terminal.focus === this;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* focus
|
* focus
|
||||||
*/
|
*/
|
||||||
@ -25,8 +17,6 @@ module.exports = function (Terminal){
|
|||||||
Terminal.focus.blur();
|
Terminal.focus.blur();
|
||||||
}
|
}
|
||||||
|
|
||||||
Terminal.focus = this;
|
|
||||||
|
|
||||||
if (this.cursor) {
|
if (this.cursor) {
|
||||||
this.showCursor();
|
this.showCursor();
|
||||||
}
|
}
|
||||||
@ -34,6 +24,8 @@ module.exports = function (Terminal){
|
|||||||
if (this.cursorBlink) {
|
if (this.cursorBlink) {
|
||||||
this.startBlink();
|
this.startBlink();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Terminal.focus = this;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,12 +29,35 @@ module.exports = function (Terminal){
|
|||||||
* open
|
* open
|
||||||
*/
|
*/
|
||||||
Terminal.prototype.open = function (){
|
Terminal.prototype.open = function (){
|
||||||
|
var div;
|
||||||
|
var i = 0;
|
||||||
|
|
||||||
|
this.element = document.createElement('div');
|
||||||
|
this.element.className = 'ui-terminal';
|
||||||
|
this.element.style.outline = 'none';
|
||||||
|
|
||||||
|
this.element.setAttribute('tabindex', '0');
|
||||||
|
this.element.setAttribute('spellcheck', 'false');
|
||||||
|
|
||||||
|
// sync default bg/fg colors
|
||||||
|
this.element.style.backgroundColor = this.bgColor;
|
||||||
|
this.element.style.color = this.fgColor;
|
||||||
|
|
||||||
|
// Create the lines for our terminal.
|
||||||
|
this.children = [];
|
||||||
|
|
||||||
|
for (; i < this.rows; i++) {
|
||||||
|
div = document.createElement('div');
|
||||||
|
|
||||||
|
this.element.appendChild(div);
|
||||||
|
this.children.push(div);
|
||||||
|
}
|
||||||
|
|
||||||
// XXX - hack, move this somewhere else.
|
// XXX - hack, move this somewhere else.
|
||||||
if (Terminal.brokenBold === null) {
|
if (Terminal.brokenBold === null) {
|
||||||
Terminal.brokenBold = isBoldBroken();
|
Terminal.brokenBold = isBoldBroken();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.refresh(0, this.rows - 1);
|
this.refresh(0, this.rows - 1);
|
||||||
this.focus();
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -11,6 +11,7 @@ module.exports = function (Terminal){
|
|||||||
Terminal.cursor = true;
|
Terminal.cursor = true;
|
||||||
Terminal.cursorBlink = true;
|
Terminal.cursorBlink = true;
|
||||||
Terminal.cursorBlinkSpeed = 500;
|
Terminal.cursorBlinkSpeed = 500;
|
||||||
|
Terminal.visualBell = true;
|
||||||
Terminal.popOnBell = true;
|
Terminal.popOnBell = true;
|
||||||
Terminal.scrollback = 640;
|
Terminal.scrollback = 640;
|
||||||
Terminal.screenKeys = false;
|
Terminal.screenKeys = false;
|
||||||
@ -23,6 +24,7 @@ module.exports = function (Terminal){
|
|||||||
cursor: Terminal.cursor,
|
cursor: Terminal.cursor,
|
||||||
cursorBlink: Terminal.cursorBlink,
|
cursorBlink: Terminal.cursorBlink,
|
||||||
cursorBlinkSpeed: Terminal.cursorBlinkSpeed,
|
cursorBlinkSpeed: Terminal.cursorBlinkSpeed,
|
||||||
|
visualBell: Terminal.visualBell,
|
||||||
popOnBell: Terminal.popOnBell,
|
popOnBell: Terminal.popOnBell,
|
||||||
scrollback: Terminal.scrollback,
|
scrollback: Terminal.scrollback,
|
||||||
screenKeys: Terminal.screenKeys,
|
screenKeys: Terminal.screenKeys,
|
||||||
|
@ -5,21 +5,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = function (Terminal){
|
module.exports = function (Terminal){
|
||||||
/**
|
|
||||||
* screen
|
|
||||||
* @param foreground
|
|
||||||
* @param background
|
|
||||||
* @param content
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
function screen(foreground, background, content){
|
|
||||||
var intro = '<div class="ui-terminal" tabindex="0" spellcheck="false" '
|
|
||||||
+ 'style="outline:none;background-color:' + background + ' ; color:' + foreground + ';">';
|
|
||||||
var outro = '</div>';
|
|
||||||
|
|
||||||
return intro + content + outro;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rendering Engine
|
// Rendering Engine
|
||||||
// In the screen buffer, each character
|
// In the screen buffer, each character
|
||||||
// is stored as a an array with a character
|
// is stored as a an array with a character
|
||||||
@ -37,8 +22,14 @@ module.exports = function (Terminal){
|
|||||||
* @param end
|
* @param end
|
||||||
*/
|
*/
|
||||||
Terminal.prototype.refresh = function (start, end){
|
Terminal.prototype.refresh = function (start, end){
|
||||||
|
var parent = this.element ? this.element.parentNode : null;
|
||||||
|
var optimize = parent && end - start >= this.rows / 2;
|
||||||
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;
|
||||||
|
|
||||||
|
if (optimize) {
|
||||||
|
parent.removeChild(this.element);
|
||||||
|
}
|
||||||
|
|
||||||
width = this.cols;
|
width = this.cols;
|
||||||
y = start;
|
y = start;
|
||||||
|
|
||||||
@ -159,11 +150,11 @@ module.exports = function (Terminal){
|
|||||||
out += '</span>';
|
out += '</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
this.screenLines[y] = '<div>' + out + '</div>';
|
this.children[y].innerHTML = out;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.screen = screen(this.fgColor, this.bgColor, this.screenLines.join(''));
|
if (optimize) {
|
||||||
|
parent.appendChild(this.element);
|
||||||
this.onscreen.call(this, this.screen);
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -11,7 +11,7 @@ module.exports = function (Terminal){
|
|||||||
* @param y
|
* @param y
|
||||||
*/
|
*/
|
||||||
Terminal.prototype.resize = function (x, y){
|
Terminal.prototype.resize = function (x, y){
|
||||||
var i, j, ch;
|
var line, element, i, j, ch;
|
||||||
|
|
||||||
if (x < 1) x = 1;
|
if (x < 1) x = 1;
|
||||||
|
|
||||||
@ -48,16 +48,34 @@ module.exports = function (Terminal){
|
|||||||
j = this.rows;
|
j = this.rows;
|
||||||
|
|
||||||
if (j < y) {
|
if (j < y) {
|
||||||
|
element = this.element;
|
||||||
|
|
||||||
while (j++ < y) {
|
while (j++ < y) {
|
||||||
if (this.lines.length < y + this.ybase) {
|
if (this.lines.length < y + this.ybase) {
|
||||||
this.lines.push(this.blankLine());
|
this.lines.push(this.blankLine());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.children.length < y) {
|
||||||
|
line = this.document.createElement('div');
|
||||||
|
|
||||||
|
element.appendChild(line);
|
||||||
|
|
||||||
|
this.children.push(line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (j > y) {
|
} else if (j > y) {
|
||||||
while (j-- > y) {
|
while (j-- > y) {
|
||||||
if (this.lines.length > y + this.ybase) {
|
if (this.lines.length > y + this.ybase) {
|
||||||
this.lines.pop();
|
this.lines.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.children.length > y) {
|
||||||
|
element = this.children.pop();
|
||||||
|
|
||||||
|
if (!element) continue;
|
||||||
|
|
||||||
|
element.parentNode.removeChild(element);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,9 +30,19 @@ module.exports = function (Terminal){
|
|||||||
*/
|
*/
|
||||||
Terminal.prototype.bell = function (){
|
Terminal.prototype.bell = function (){
|
||||||
// buffers automatically when created
|
// buffers automatically when created
|
||||||
var bell = new Audio('bell.wav');
|
var snd = new Audio('bell.wav');
|
||||||
|
|
||||||
bell.play();
|
snd.play();
|
||||||
|
|
||||||
|
if (!this.visualBell) return;
|
||||||
|
|
||||||
|
var context = this;
|
||||||
|
|
||||||
|
this.element.style.borderColor = 'white';
|
||||||
|
|
||||||
|
setTimeout(function (){
|
||||||
|
context.element.style.borderColor = '';
|
||||||
|
}, 10);
|
||||||
|
|
||||||
if (this.popOnBell) this.focus();
|
if (this.popOnBell) this.focus();
|
||||||
};
|
};
|
||||||
@ -414,6 +424,7 @@ module.exports = function (Terminal){
|
|||||||
case 2:
|
case 2:
|
||||||
if (this.params[1]) {
|
if (this.params[1]) {
|
||||||
this.title = this.params[1];
|
this.title = this.params[1];
|
||||||
|
|
||||||
this.ontitle.call(this, this.title);
|
this.ontitle.call(this, this.title);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user