mirror of
https://github.com/nuintun/command-manager.git
synced 2025-06-08 04:04:04 +08:00
update files
This commit is contained in:
parent
d3b1f33b9f
commit
4f037c405f
@ -110,8 +110,8 @@ function Terminal(options){
|
|||||||
this.charsets = [null];
|
this.charsets = [null];
|
||||||
|
|
||||||
// misc
|
// misc
|
||||||
this.element = null;
|
this.screen = '';
|
||||||
this.children = [];
|
this.screenLines = [];
|
||||||
this.refreshStart = null;
|
this.refreshStart = null;
|
||||||
this.refreshEnd = null;
|
this.refreshEnd = null;
|
||||||
this.savedX = null;
|
this.savedX = null;
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
module.exports = function (Terminal){
|
module.exports = function (Terminal){
|
||||||
/**
|
/**
|
||||||
* blankLine
|
* blankLine
|
||||||
* @param cur
|
* @param [cur]
|
||||||
* @returns {Array}
|
* @returns {Array}
|
||||||
*/
|
*/
|
||||||
Terminal.prototype.blankLine = function (cur){
|
Terminal.prototype.blankLine = function (cur){
|
||||||
|
@ -10,21 +10,12 @@ module.exports = function (Terminal){
|
|||||||
*/
|
*/
|
||||||
Terminal.prototype.close = function (){
|
Terminal.prototype.close = function (){
|
||||||
this.lines = [];
|
this.lines = [];
|
||||||
this.children = [];
|
this.screen = '';
|
||||||
|
this.screenLines = [];
|
||||||
this.readable = false;
|
this.readable = false;
|
||||||
this.writable = false;
|
this.writable = false;
|
||||||
this.write = function (){};
|
this.write = function (){};
|
||||||
this.handler = function (){};
|
this.handler = function (){};
|
||||||
this.handlerTitle = function (){};
|
this.handlerTitle = function (){};
|
||||||
|
|
||||||
if (this.element) {
|
|
||||||
var parent = this.element.parentNode;
|
|
||||||
|
|
||||||
if (parent) {
|
|
||||||
parent.removeChild(this.element);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.element = null;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -29,35 +29,11 @@ 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.refresh(0, this.rows - 1);
|
|
||||||
|
|
||||||
// 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);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -16,20 +16,22 @@ module.exports = function (Terminal){
|
|||||||
// Next 14 bits: a mask for misc.
|
// Next 14 bits: a mask for misc.
|
||||||
// flags: 1=bold, 2=underline, 4=blink, 8=inverse, 16=invisible
|
// flags: 1=bold, 2=underline, 4=blink, 8=inverse, 16=invisible
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* refresh
|
* refresh
|
||||||
* @param start
|
* @param start
|
||||||
* @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;
|
||||||
|
|
||||||
@ -150,11 +152,9 @@ module.exports = function (Terminal){
|
|||||||
out += '</span>';
|
out += '</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
this.children[y].innerHTML = out;
|
this.screenLines[y] = '<div>' + out + '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optimize) {
|
this.screen = screen(this.fgColor, this.bgColor, this.screenLines.join(''));
|
||||||
parent.appendChild(this.element);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -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 line, element, i, j, ch;
|
var line, i, j, ch;
|
||||||
|
|
||||||
if (x < 1) x = 1;
|
if (x < 1) x = 1;
|
||||||
|
|
||||||
@ -48,33 +48,16 @@ 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user