From 8d2af4a4330c21bf83f4200dbac34dcd55b0868e Mon Sep 17 00:00:00 2001 From: nuintun Date: Thu, 26 Nov 2015 11:45:31 +0800 Subject: [PATCH] update files --- static/js/terminal/index.js | 1 + static/js/terminal/lib/csi/erase.js | 73 +++++++++++++++++++++++ static/js/terminal/lib/debug.js | 6 ++ static/js/terminal/lib/erase.js | 84 ++++++--------------------- static/js/terminal/lib/focused.js | 6 ++ static/js/terminal/lib/open.js | 4 +- static/js/terminal/lib/range.js | 7 +++ static/js/terminal/lib/refresh.js | 27 +++++---- static/js/terminal/lib/resize.js | 7 ++- static/js/terminal/lib/scrollDisp.js | 7 +++ static/js/terminal/lib/setgCharset.js | 5 ++ static/js/terminal/lib/setgLevel.js | 4 ++ static/js/terminal/lib/util.js | 15 +++++ static/js/terminal/lib/write.js | 14 ++++- 14 files changed, 178 insertions(+), 82 deletions(-) create mode 100644 static/js/terminal/lib/csi/erase.js diff --git a/static/js/terminal/index.js b/static/js/terminal/index.js index 0431e38..987f3f1 100644 --- a/static/js/terminal/index.js +++ b/static/js/terminal/index.js @@ -180,6 +180,7 @@ require('./lib/esc/tabSet.js')(Terminal); require('./lib/charsets.js')(Terminal); require('./lib/csi/charAttributes')(Terminal); +require('./lib/csi/erase')(Terminal); require('./lib/csi/insert-delete')(Terminal); require('./lib/csi/position')(Terminal); require('./lib/csi/cursor')(Terminal); diff --git a/static/js/terminal/lib/csi/erase.js b/static/js/terminal/lib/csi/erase.js new file mode 100644 index 0000000..7d18cf8 --- /dev/null +++ b/static/js/terminal/lib/csi/erase.js @@ -0,0 +1,73 @@ +/** + * Created by nuintun on 2015/11/24. + */ + +'use strict'; + +module.exports = function (Terminal){ + // CSI Ps J Erase in Display (ED). + // Ps = 0 -> Erase Below (default). + // Ps = 1 -> Erase Above. + // Ps = 2 -> Erase All. + // Ps = 3 -> Erase Saved Lines (xterm). + // CSI ? Ps J + // Erase in Display (DECSED). + // Ps = 0 -> Selective Erase Below (default). + // Ps = 1 -> Selective Erase Above. + // Ps = 2 -> Selective Erase All. + Terminal.prototype.eraseInDisplay = function (params){ + var j; + + switch (params[0]) { + case 0: + this.eraseRight(this.x, this.y); + + j = this.y + 1; + + for (; j < this.rows; j++) { + this.eraseLine(j); + } + break; + case 1: + this.eraseLeft(this.x, this.y); + + j = this.y; + + while (j--) { + this.eraseLine(j); + } + break; + case 2: + j = this.rows; + + while (j--) this.eraseLine(j); + break; + case 3: + // no saved lines + break; + } + }; + + // CSI Ps K Erase in Line (EL). + // Ps = 0 -> Erase to Right (default). + // Ps = 1 -> Erase to Left. + // Ps = 2 -> Erase All. + // CSI ? Ps K + // Erase in Line (DECSEL). + // Ps = 0 -> Selective Erase to Right (default). + // Ps = 1 -> Selective Erase to Left. + // Ps = 2 -> Selective Erase All. + Terminal.prototype.eraseInLine = function (params){ + switch (params[0]) { + case 0: + this.eraseRight(this.x, this.y); + break; + case 1: + this.eraseLeft(this.x, this.y); + break; + case 2: + this.eraseLine(this.y); + break; + } + }; +}; diff --git a/static/js/terminal/lib/debug.js b/static/js/terminal/lib/debug.js index 1893b9b..1b03750 100644 --- a/static/js/terminal/lib/debug.js +++ b/static/js/terminal/lib/debug.js @@ -5,6 +5,9 @@ 'use strict'; module.exports = function (Terminal){ + /** + * log + */ Terminal.prototype.log = function (){ if (!this.debug) return; @@ -15,6 +18,9 @@ module.exports = function (Terminal){ window.console.log.apply(window.console, args); }; + /** + * error + */ Terminal.prototype.error = function (){ if (!this.debug) return; diff --git a/static/js/terminal/lib/erase.js b/static/js/terminal/lib/erase.js index 8694527..623f37c 100644 --- a/static/js/terminal/lib/erase.js +++ b/static/js/terminal/lib/erase.js @@ -5,10 +5,19 @@ 'use strict'; module.exports = function (Terminal){ + /** + * eraseAttr + * @returns {number} + */ Terminal.prototype.eraseAttr = function (){ return (this.defAttr & ~0x1ff) | (this.curAttr & 0x1ff); }; + /** + * eraseRight + * @param x + * @param y + */ Terminal.prototype.eraseRight = function (x, y){ var line = this.lines[this.ybase + y]; var ch = [this.eraseAttr(), ' ']; @@ -20,6 +29,11 @@ module.exports = function (Terminal){ this.updateRange(y); }; + /** + * eraseLeft + * @param x + * @param y + */ Terminal.prototype.eraseLeft = function (x, y){ var line = this.lines[this.ybase + y]; var ch = [this.eraseAttr(), ' ']; @@ -31,73 +45,11 @@ module.exports = function (Terminal){ this.updateRange(y); }; + /** + * eraseLine + * @param y + */ Terminal.prototype.eraseLine = function (y){ this.eraseRight(0, y); }; - - // CSI Ps J Erase in Display (ED). - // Ps = 0 -> Erase Below (default). - // Ps = 1 -> Erase Above. - // Ps = 2 -> Erase All. - // Ps = 3 -> Erase Saved Lines (xterm). - // CSI ? Ps J - // Erase in Display (DECSED). - // Ps = 0 -> Selective Erase Below (default). - // Ps = 1 -> Selective Erase Above. - // Ps = 2 -> Selective Erase All. - Terminal.prototype.eraseInDisplay = function (params){ - var j; - - switch (params[0]) { - case 0: - this.eraseRight(this.x, this.y); - - j = this.y + 1; - - for (; j < this.rows; j++) { - this.eraseLine(j); - } - break; - case 1: - this.eraseLeft(this.x, this.y); - - j = this.y; - - while (j--) { - this.eraseLine(j); - } - break; - case 2: - j = this.rows; - - while (j--) this.eraseLine(j); - break; - case 3: - // no saved lines - break; - } - }; - - // CSI Ps K Erase in Line (EL). - // Ps = 0 -> Erase to Right (default). - // Ps = 1 -> Erase to Left. - // Ps = 2 -> Erase All. - // CSI ? Ps K - // Erase in Line (DECSEL). - // Ps = 0 -> Selective Erase to Right (default). - // Ps = 1 -> Selective Erase to Left. - // Ps = 2 -> Selective Erase All. - Terminal.prototype.eraseInLine = function (params){ - switch (params[0]) { - case 0: - this.eraseRight(this.x, this.y); - break; - case 1: - this.eraseLeft(this.x, this.y); - break; - case 2: - this.eraseLine(this.y); - break; - } - }; }; diff --git a/static/js/terminal/lib/focused.js b/static/js/terminal/lib/focused.js index c4cd433..7e4a494 100644 --- a/static/js/terminal/lib/focused.js +++ b/static/js/terminal/lib/focused.js @@ -7,6 +7,9 @@ module.exports = function (Terminal){ Terminal.focus = null; + /** + * focus + */ Terminal.prototype.focus = function (){ if (Terminal.focus === this) return; @@ -25,6 +28,9 @@ module.exports = function (Terminal){ Terminal.focus = this; }; + /** + * blur + */ Terminal.prototype.blur = function (){ if (Terminal.focus !== this) return; diff --git a/static/js/terminal/lib/open.js b/static/js/terminal/lib/open.js index 52b58d1..ffe87d3 100644 --- a/static/js/terminal/lib/open.js +++ b/static/js/terminal/lib/open.js @@ -26,7 +26,7 @@ function isBoldBroken(){ module.exports = function (Terminal){ /** - * Open Terminal + * open */ Terminal.prototype.open = function (){ var div; @@ -38,7 +38,7 @@ module.exports = function (Terminal){ 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; diff --git a/static/js/terminal/lib/range.js b/static/js/terminal/lib/range.js index 5b4802b..3e8191e 100644 --- a/static/js/terminal/lib/range.js +++ b/static/js/terminal/lib/range.js @@ -5,12 +5,19 @@ 'use strict'; module.exports = function (Terminal){ + /** + * updateRange + * @param y + */ Terminal.prototype.updateRange = function (y){ if (y < this.refreshStart) this.refreshStart = y; if (y > this.refreshEnd) this.refreshEnd = y; }; + /** + * maxRange + */ Terminal.prototype.maxRange = function (){ this.refreshStart = 0; this.refreshEnd = this.rows - 1; diff --git a/static/js/terminal/lib/refresh.js b/static/js/terminal/lib/refresh.js index dbb6bfb..45da263 100644 --- a/static/js/terminal/lib/refresh.js +++ b/static/js/terminal/lib/refresh.js @@ -5,19 +5,22 @@ 'use strict'; module.exports = function (Terminal){ - /** - * Rendering Engine - */ + // Rendering Engine + // In the screen buffer, each character + // is stored as a an array with a character + // and a 32-bit integer. + // First value: a utf-16 character. + // Second value: + // Next 9 bits: background color (0-511). + // Next 9 bits: foreground color (0-511). + // Next 14 bits: a mask for misc. + // flags: 1=bold, 2=underline, 4=blink, 8=inverse, 16=invisible - // In the screen buffer, each character - // is stored as a an array with a character - // and a 32-bit integer. - // First value: a utf-16 character. - // Second value: - // Next 9 bits: background color (0-511). - // Next 9 bits: foreground color (0-511). - // Next 14 bits: a mask for misc. - // flags: 1=bold, 2=underline, 4=blink, 8=inverse, 16=invisible + /** + * refresh + * @param start + * @param end + */ Terminal.prototype.refresh = function (start, end){ var parent = this.element.parentNode; var x, y, i, line, out, ch, width, data, attr, fgColor, bgColor, flags, row; diff --git a/static/js/terminal/lib/resize.js b/static/js/terminal/lib/resize.js index 7833af4..efdd7b9 100644 --- a/static/js/terminal/lib/resize.js +++ b/static/js/terminal/lib/resize.js @@ -5,11 +5,16 @@ 'use strict'; module.exports = function (Terminal){ + /** + * resize + * @param x + * @param y + */ Terminal.prototype.resize = function (x, y){ var line, element, i, j, ch; if (x < 1) x = 1; - + if (y < 1) y = 1; // resize cols diff --git a/static/js/terminal/lib/scrollDisp.js b/static/js/terminal/lib/scrollDisp.js index ad644fc..05f71f5 100644 --- a/static/js/terminal/lib/scrollDisp.js +++ b/static/js/terminal/lib/scrollDisp.js @@ -5,6 +5,9 @@ 'use strict'; module.exports = function (Terminal){ + /** + * scroll + */ Terminal.prototype.scroll = function (){ var row; @@ -45,6 +48,10 @@ module.exports = function (Terminal){ this.updateRange(this.scrollBottom); }; + /** + * scrollDisp + * @param disp + */ Terminal.prototype.scrollDisp = function (disp){ this.ydisp += disp; diff --git a/static/js/terminal/lib/setgCharset.js b/static/js/terminal/lib/setgCharset.js index d293aa3..ec599ed 100644 --- a/static/js/terminal/lib/setgCharset.js +++ b/static/js/terminal/lib/setgCharset.js @@ -5,6 +5,11 @@ 'use strict'; module.exports = function (Terminal){ + /** + * setgCharset + * @param g + * @param charset + */ Terminal.prototype.setgCharset = function (g, charset){ this.charsets[g] = charset; diff --git a/static/js/terminal/lib/setgLevel.js b/static/js/terminal/lib/setgLevel.js index 957428e..ee23e75 100644 --- a/static/js/terminal/lib/setgLevel.js +++ b/static/js/terminal/lib/setgLevel.js @@ -5,6 +5,10 @@ 'use strict'; module.exports = function (Terminal){ + /** + * setgLevel + * @param g + */ Terminal.prototype.setgLevel = function (g){ this.glevel = g; this.charset = this.charsets[g]; diff --git a/static/js/terminal/lib/util.js b/static/js/terminal/lib/util.js index 58de14d..9745d25 100644 --- a/static/js/terminal/lib/util.js +++ b/static/js/terminal/lib/util.js @@ -5,6 +5,11 @@ 'use strict'; module.exports = function (Terminal){ + /** + * isWide + * @param ch + * @returns {boolean} + */ Terminal.prototype.isWide = function isWide(ch){ if (ch <= '\uff00') return false; @@ -17,10 +22,20 @@ module.exports = function (Terminal){ || (ch >= '\uffe8' && ch <= '\uffee'); }; + /** + * ch + * @param cur + * @returns {string[]} + */ Terminal.prototype.ch = function (cur){ return cur ? [this.eraseAttr(), ' '] : [this.defAttr, ' ']; }; + /** + * is + * @param term + * @returns {boolean} + */ Terminal.prototype.is = function (term){ var name = this.termName; diff --git a/static/js/terminal/lib/write.js b/static/js/terminal/lib/write.js index d4510f0..732ffe0 100644 --- a/static/js/terminal/lib/write.js +++ b/static/js/terminal/lib/write.js @@ -7,6 +7,10 @@ var states = require('./states'); module.exports = function (Terminal){ + /** + * send + * @param data + */ Terminal.prototype.send = function (data){ var context = this; @@ -21,8 +25,12 @@ module.exports = function (Terminal){ this.queue += data; }; + /** + * bell + */ Terminal.prototype.bell = function (){ - var snd = new Audio('bell.wav'); // buffers automatically when created + // buffers automatically when created + var snd = new Audio('bell.wav'); snd.play(); @@ -39,6 +47,10 @@ module.exports = function (Terminal){ if (this.popOnBell) this.focus(); }; + /** + * write + * @param data + */ Terminal.prototype.write = function (data){ var l = data.length; var i = 0;