update files

This commit is contained in:
nuintun 2015-11-26 21:43:25 +08:00
parent d3b1f33b9f
commit 4f037c405f
6 changed files with 18 additions and 68 deletions

View File

@ -110,8 +110,8 @@ function Terminal(options){
this.charsets = [null];
// misc
this.element = null;
this.children = [];
this.screen = '';
this.screenLines = [];
this.refreshStart = null;
this.refreshEnd = null;
this.savedX = null;

View File

@ -7,7 +7,7 @@
module.exports = function (Terminal){
/**
* blankLine
* @param cur
* @param [cur]
* @returns {Array}
*/
Terminal.prototype.blankLine = function (cur){

View File

@ -10,21 +10,12 @@ module.exports = function (Terminal){
*/
Terminal.prototype.close = function (){
this.lines = [];
this.children = [];
this.screen = '';
this.screenLines = [];
this.readable = false;
this.writable = false;
this.write = function (){};
this.handler = function (){};
this.handlerTitle = function (){};
if (this.element) {
var parent = this.element.parentNode;
if (parent) {
parent.removeChild(this.element);
}
this.element = null;
}
};
};

View File

@ -29,35 +29,11 @@ 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);
}
this.refresh(0, this.rows - 1);
// XXX - hack, move this somewhere else.
if (Terminal.brokenBold === null) {
Terminal.brokenBold = isBoldBroken();
}
this.refresh(0, this.rows - 1);
};
};

View File

@ -16,20 +16,22 @@ module.exports = function (Terminal){
// Next 14 bits: a mask for misc.
// 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
* @param start
* @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;
@ -150,11 +152,9 @@ module.exports = function (Terminal){
out += '</span>';
}
this.children[y].innerHTML = out;
this.screenLines[y] = '<div>' + out + '</div>';
}
if (optimize) {
parent.appendChild(this.element);
}
this.screen = screen(this.fgColor, this.bgColor, this.screenLines.join(''));
};
};

View File

@ -11,7 +11,7 @@ module.exports = function (Terminal){
* @param y
*/
Terminal.prototype.resize = function (x, y){
var line, element, i, j, ch;
var line, i, j, ch;
if (x < 1) x = 1;
@ -48,33 +48,16 @@ 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);
}
}
}