From 4f037c405faa7fae459f188745b904e22e1d08fa Mon Sep 17 00:00:00 2001 From: nuintun Date: Thu, 26 Nov 2015 21:43:25 +0800 Subject: [PATCH] update files --- static/js/terminal/index.js | 4 ++-- static/js/terminal/lib/blankLine.js | 2 +- static/js/terminal/lib/close.js | 13 ++----------- static/js/terminal/lib/open.js | 28 ++-------------------------- static/js/terminal/lib/refresh.js | 20 ++++++++++---------- static/js/terminal/lib/resize.js | 19 +------------------ 6 files changed, 18 insertions(+), 68 deletions(-) diff --git a/static/js/terminal/index.js b/static/js/terminal/index.js index cc15b63..9c8b554 100644 --- a/static/js/terminal/index.js +++ b/static/js/terminal/index.js @@ -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; diff --git a/static/js/terminal/lib/blankLine.js b/static/js/terminal/lib/blankLine.js index 0612038..059f503 100644 --- a/static/js/terminal/lib/blankLine.js +++ b/static/js/terminal/lib/blankLine.js @@ -7,7 +7,7 @@ module.exports = function (Terminal){ /** * blankLine - * @param cur + * @param [cur] * @returns {Array} */ Terminal.prototype.blankLine = function (cur){ diff --git a/static/js/terminal/lib/close.js b/static/js/terminal/lib/close.js index f4defa6..0b6ca9e 100644 --- a/static/js/terminal/lib/close.js +++ b/static/js/terminal/lib/close.js @@ -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; - } }; }; diff --git a/static/js/terminal/lib/open.js b/static/js/terminal/lib/open.js index ffe87d3..09412fc 100644 --- a/static/js/terminal/lib/open.js +++ b/static/js/terminal/lib/open.js @@ -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); }; }; diff --git a/static/js/terminal/lib/refresh.js b/static/js/terminal/lib/refresh.js index e1e72ef..15d701d 100644 --- a/static/js/terminal/lib/refresh.js +++ b/static/js/terminal/lib/refresh.js @@ -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 = '
'; + var outro = '
'; + + 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 += ''; } - this.children[y].innerHTML = out; + this.screenLines[y] = '
' + out + '
'; } - if (optimize) { - parent.appendChild(this.element); - } + this.screen = screen(this.fgColor, this.bgColor, this.screenLines.join('')); }; }; diff --git a/static/js/terminal/lib/resize.js b/static/js/terminal/lib/resize.js index efdd7b9..c3e393c 100644 --- a/static/js/terminal/lib/resize.js +++ b/static/js/terminal/lib/resize.js @@ -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); - } } }