mirror of
https://github.com/nuintun/command-manager.git
synced 2025-06-06 10:54:07 +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.rows = options.rows;
|
||||
|
||||
// set ondata
|
||||
// set on data callback
|
||||
options.ondata = typeof options.ondata === 'function' ? options.ondata : function (){};
|
||||
this.ondata = options.ondata;
|
||||
|
||||
// set ontitle
|
||||
// set on title callback
|
||||
options.ontitle = typeof options.ontitle === 'function' ? options.ontitle : function (){};
|
||||
this.ontitle = options.ontitle;
|
||||
|
||||
// set onscreen
|
||||
options.onscreen = typeof options.onscreen === 'function' ? options.onscreen : function (){};
|
||||
this.onscreen = options.onscreen;
|
||||
|
||||
// set convert eol
|
||||
// set convert end of line
|
||||
options.convertEOL = options.convertEOL === true;
|
||||
this.convertEOL = options.convertEOL;
|
||||
|
||||
@ -114,8 +110,8 @@ function Terminal(options){
|
||||
this.charsets = [null];
|
||||
|
||||
// misc
|
||||
this.screen = '';
|
||||
this.screenLines = [];
|
||||
this.element = null;
|
||||
this.children = [];
|
||||
this.refreshStart = null;
|
||||
this.refreshEnd = null;
|
||||
this.savedX = null;
|
||||
|
@ -10,13 +10,21 @@ module.exports = function (Terminal){
|
||||
*/
|
||||
Terminal.prototype.close = function (){
|
||||
this.lines = [];
|
||||
this.screen = '';
|
||||
this.screenLines = [];
|
||||
this.children = [];
|
||||
this.readable = false;
|
||||
this.writable = false;
|
||||
this.write = function (){};
|
||||
this.ondata = function (){};
|
||||
this.ontitle = function (){};
|
||||
this.onscreen = function (){};
|
||||
this.ondataTitle = 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;
|
||||
break;
|
||||
case 20:
|
||||
this.convertEol = true;
|
||||
this.convertEOL = true;
|
||||
break;
|
||||
}
|
||||
} else if (this.prefix === '?') {
|
||||
@ -322,7 +322,7 @@ module.exports = function (Terminal){
|
||||
this.insertMode = false;
|
||||
break;
|
||||
case 20:
|
||||
this.convertEol = false;
|
||||
this.convertEOL = false;
|
||||
break;
|
||||
}
|
||||
} else if (this.prefix === '?') {
|
||||
|
@ -7,14 +7,6 @@
|
||||
module.exports = function (Terminal){
|
||||
Terminal.focus = null;
|
||||
|
||||
/**
|
||||
* isFocused
|
||||
* @returns {boolean}
|
||||
*/
|
||||
Terminal.prototype.isFocused = function (){
|
||||
return Terminal.focus === this;
|
||||
};
|
||||
|
||||
/**
|
||||
* focus
|
||||
*/
|
||||
@ -25,8 +17,6 @@ module.exports = function (Terminal){
|
||||
Terminal.focus.blur();
|
||||
}
|
||||
|
||||
Terminal.focus = this;
|
||||
|
||||
if (this.cursor) {
|
||||
this.showCursor();
|
||||
}
|
||||
@ -34,6 +24,8 @@ module.exports = function (Terminal){
|
||||
if (this.cursorBlink) {
|
||||
this.startBlink();
|
||||
}
|
||||
|
||||
Terminal.focus = this;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -29,12 +29,35 @@ module.exports = function (Terminal){
|
||||
* open
|
||||
*/
|
||||
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.
|
||||
if (Terminal.brokenBold === null) {
|
||||
Terminal.brokenBold = isBoldBroken();
|
||||
}
|
||||
|
||||
this.refresh(0, this.rows - 1);
|
||||
this.focus();
|
||||
};
|
||||
};
|
||||
|
@ -11,6 +11,7 @@ module.exports = function (Terminal){
|
||||
Terminal.cursor = true;
|
||||
Terminal.cursorBlink = true;
|
||||
Terminal.cursorBlinkSpeed = 500;
|
||||
Terminal.visualBell = true;
|
||||
Terminal.popOnBell = true;
|
||||
Terminal.scrollback = 640;
|
||||
Terminal.screenKeys = false;
|
||||
@ -23,6 +24,7 @@ module.exports = function (Terminal){
|
||||
cursor: Terminal.cursor,
|
||||
cursorBlink: Terminal.cursorBlink,
|
||||
cursorBlinkSpeed: Terminal.cursorBlinkSpeed,
|
||||
visualBell: Terminal.visualBell,
|
||||
popOnBell: Terminal.popOnBell,
|
||||
scrollback: Terminal.scrollback,
|
||||
screenKeys: Terminal.screenKeys,
|
||||
|
@ -5,21 +5,6 @@
|
||||
'use strict';
|
||||
|
||||
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
|
||||
// In the screen buffer, each character
|
||||
// is stored as a an array with a character
|
||||
@ -37,8 +22,14 @@ module.exports = function (Terminal){
|
||||
* @param 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;
|
||||
|
||||
if (optimize) {
|
||||
parent.removeChild(this.element);
|
||||
}
|
||||
|
||||
width = this.cols;
|
||||
y = start;
|
||||
|
||||
@ -159,11 +150,11 @@ module.exports = function (Terminal){
|
||||
out += '</span>';
|
||||
}
|
||||
|
||||
this.screenLines[y] = '<div>' + out + '</div>';
|
||||
this.children[y].innerHTML = out;
|
||||
}
|
||||
|
||||
this.screen = screen(this.fgColor, this.bgColor, this.screenLines.join(''));
|
||||
|
||||
this.onscreen.call(this, this.screen);
|
||||
if (optimize) {
|
||||
parent.appendChild(this.element);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
@ -11,7 +11,7 @@ module.exports = function (Terminal){
|
||||
* @param y
|
||||
*/
|
||||
Terminal.prototype.resize = function (x, y){
|
||||
var i, j, ch;
|
||||
var line, element, i, j, ch;
|
||||
|
||||
if (x < 1) x = 1;
|
||||
|
||||
@ -48,16 +48,34 @@ module.exports = function (Terminal){
|
||||
j = this.rows;
|
||||
|
||||
if (j < y) {
|
||||
element = this.element;
|
||||
|
||||
while (j++ < y) {
|
||||
if (this.lines.length < y + this.ybase) {
|
||||
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) {
|
||||
while (j-- > y) {
|
||||
if (this.lines.length > y + this.ybase) {
|
||||
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 (){
|
||||
// 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();
|
||||
};
|
||||
@ -414,6 +424,7 @@ module.exports = function (Terminal){
|
||||
case 2:
|
||||
if (this.params[1]) {
|
||||
this.title = this.params[1];
|
||||
|
||||
this.ontitle.call(this, this.title);
|
||||
}
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user