From a6d641622b31566c3064efa376a8a2f7abed2f05 Mon Sep 17 00:00:00 2001 From: nuintun Date: Fri, 27 Nov 2015 13:38:03 +0800 Subject: [PATCH] update files --- static/js/terminal/index.js | 14 +++-- static/js/terminal/lib/colors.js | 59 +++++++++++++------- static/js/terminal/lib/csi/charAttributes.js | 18 +++--- static/js/terminal/lib/open.js | 7 ++- 4 files changed, 60 insertions(+), 38 deletions(-) diff --git a/static/js/terminal/index.js b/static/js/terminal/index.js index aac25d4..dfd135e 100644 --- a/static/js/terminal/index.js +++ b/static/js/terminal/index.js @@ -47,22 +47,28 @@ function Terminal(options){ if (Array.isArray(options.colors)) { if (options.colors.length === 8) { options.colors = options.colors.concat(Terminal.colors.slice(8)); + this.vcolors = Terminal.makeVcolors(options.colors); } else if (options.colors.length === 16) { options.colors = options.colors.concat(Terminal.colors.slice(16)); + this.vcolors = Terminal.makeVcolors(options.colors); } else if (options.colors.length === 10) { options.colors = options.colors.slice(0, -2).concat(Terminal.colors.slice(8, -2), options.colors.slice(-2)); + this.vcolors = Terminal.makeVcolors(options.colors); } else if (options.colors.length === 18) { options.colors = options.colors.slice(0, -2).concat(Terminal.colors.slice(16, -2), options.colors.slice(-2)); + this.vcolors = Terminal.makeVcolors(options.colors); } else { - options.colors = Terminal.colors; + options.colors = Terminal.colors.slice(); + this.vcolors = Terminal.vcolors.slice(); } } else { - options.colors = Terminal.colors; + options.colors = Terminal.colors.slice(); + this.vcolors = Terminal.vcolors.slice(); } this.colors = options.colors; - this.bgColor = options.bgColor || Terminal.defaultColors.bgColor; - this.fgColor = options.fgColor || Terminal.defaultColors.fgColor; + this.background = options.background || Terminal.defaultColors.background; + this.foreground = options.foreground || Terminal.defaultColors.foreground; // set screen size options.cols = options.cols || Terminal.geometry[0]; diff --git a/static/js/terminal/lib/colors.js b/static/js/terminal/lib/colors.js index 2fdb583..bbd8ce2 100644 --- a/static/js/terminal/lib/colors.js +++ b/static/js/terminal/lib/colors.js @@ -5,21 +5,44 @@ 'use strict'; module.exports = function (Terminal){ - // Colors 0-15 - Terminal.colors = [ - // dark: - '#2e3436', '#cc0000', '#4e9a06', '#c4a000', '#3465a4', '#75507b', '#06989a', '#d3d7cf', - // bright: - '#555753', '#ef2929', '#8ae234', '#fce94f', '#729fcf', '#ad7fa8', '#34e2e2', '#eeeeec' - ]; + // Default colors + Terminal.defaultColors = { + // Colors 0-15 + colors: [ + // dark: + '#000000', // black + '#cd0000', // red3 + '#00cd00', // green3 + '#cdcd00', // yellow3 + '#0000ee', // blue2 + '#cd00cd', // magenta3 + '#00cdcd', // cyan3 + '#e5e5e5', // gray90 + // bright: + '#7f7f7f', // gray50 + '#ff0000', // red + '#00ff00', // green + '#ffff00', // yellow + '#5c5cff', // rgb:5c/5c/ff + '#ff00ff', // magenta + '#00ffff', // cyan + '#ffffff' // white + ], + // Default background color + background: '#181818', + // Default foreground color + foreground: '#ffffff' + }; // Colors 16-255 // Much thanks to TooTallNate for writing this. - Terminal.colors = (function (){ + Terminal.makeColors = function (colors){ var i; - var colors = Terminal.colors; var r = [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff]; + // copy colors + colors = colors.slice(); + // 16-231 i = 0; @@ -46,13 +69,13 @@ module.exports = function (Terminal){ } return colors; - })(); + }; - Terminal.vcolors = (function (){ + // Vcolors 0-255 + Terminal.makeVcolors = function (colors){ var color; var i = 0; var out = []; - var colors = Terminal.colors; for (; i < 256; i++) { color = parseInt(colors[i].substring(1), 16); @@ -61,14 +84,10 @@ module.exports = function (Terminal){ } return out; - })(); - - // Default BG/FG - Terminal.defaultColors = { - bgColor: '#000000', - fgColor: '#f0f0f0' }; - Terminal.colors[256] = Terminal.defaultColors.bgColor; - Terminal.colors[257] = Terminal.defaultColors.fgColor; + // Colors 0-255 + Terminal.colors = Terminal.makeColors(Terminal.defaultColors.colors); + // Vcolors 0-255 + Terminal.vcolors = Terminal.makeVcolors(Terminal.colors); }; diff --git a/static/js/terminal/lib/csi/charAttributes.js b/static/js/terminal/lib/csi/charAttributes.js index 602f465..92ad7bb 100644 --- a/static/js/terminal/lib/csi/charAttributes.js +++ b/static/js/terminal/lib/csi/charAttributes.js @@ -7,12 +7,13 @@ module.exports = function (Terminal){ /** * matchColor + * @param vcolors * @param r1 * @param g1 * @param b1 * @returns {*} */ - function matchColor(r1, g1, b1){ + function matchColor(vcolors, r1, g1, b1){ var hash = (r1 << 16) | (g1 << 8) | b1; if (matchColor._cache.hasOwnProperty(hash + '')) { @@ -24,8 +25,8 @@ module.exports = function (Terminal){ var ldiff = Infinity; var c, r2, g2, b2, diff; - for (; i < Terminal.vcolors.length; i++) { - c = Terminal.vcolors[i]; + for (; i < vcolors.length; i++) { + c = vcolors[i]; r2 = c[0]; g2 = c[1]; b2 = c[2]; @@ -121,6 +122,7 @@ module.exports = function (Terminal){ // Optimize a single SGR0. if (params.length === 1 && params[0] === 0) { this.curAttr = this.defAttr; + return; } @@ -198,10 +200,7 @@ module.exports = function (Terminal){ if (params[i + 1] === 2) { i += 2; - fg = matchColor( - params[i] & 0xff, - params[i + 1] & 0xff, - params[i + 2] & 0xff); + fg = matchColor(this.vcolors, params[i] & 0xff, params[i + 1] & 0xff, params[i + 2] & 0xff); if (fg === -1) fg = 0x1ff; @@ -216,10 +215,7 @@ module.exports = function (Terminal){ if (params[i + 1] === 2) { i += 2; - bg = matchColor( - params[i] & 0xff, - params[i + 1] & 0xff, - params[i + 2] & 0xff); + bg = matchColor(this.vcolors, params[i] & 0xff, params[i + 1] & 0xff, params[i + 2] & 0xff); if (bg === -1) bg = 0x1ff; diff --git a/static/js/terminal/lib/open.js b/static/js/terminal/lib/open.js index 77a3eee..1e0e4c1 100644 --- a/static/js/terminal/lib/open.js +++ b/static/js/terminal/lib/open.js @@ -40,17 +40,18 @@ module.exports = function (Terminal){ this.screen.setAttribute('spellcheck', 'false'); // sync default bg/fg colors - this.screen.style.backgroundColor = this.bgColor; - this.screen.style.color = this.fgColor; + this.screen.style.backgroundColor = this.background; + this.screen.style.color = this.foreground; // Create the lines for our terminal. this.children = []; for (; i < this.rows; i++) { div = document.createElement('div'); + div.className = 'ui-terminal-row'; - this.screen.appendChild(div); this.children.push(div); + this.screen.appendChild(div); } // XXX - hack, move this somewhere else.