From 8694c71a1b79d02b4d337e63d6d622625bf0a119 Mon Sep 17 00:00:00 2001 From: nuintun Date: Wed, 25 Nov 2015 10:59:33 +0800 Subject: [PATCH] update files --- static/css/index.css | 4 +-- static/js/components/app-main/index.js | 2 +- static/js/terminal/index.js | 44 +++++++++++++++++++++++--- static/js/terminal/lib/cursor.js | 8 ++--- static/js/terminal/lib/options.js | 11 +++++++ static/js/terminal/lib/refresh.js | 4 +-- 6 files changed, 59 insertions(+), 14 deletions(-) diff --git a/static/css/index.css b/static/css/index.css index a9dd117..483480e 100644 --- a/static/css/index.css +++ b/static/css/index.css @@ -494,6 +494,6 @@ header [class*=" icon-"] { height: calc(100% - 32px); background: url(../images/no-data.png) center no-repeat; } -.ui-terminal-cursor:before { - content: "_"; +.ui-terminal-cursor { + text-decoration: underline; } diff --git a/static/js/components/app-main/index.js b/static/js/components/app-main/index.js index a473249..3d88667 100644 --- a/static/js/components/app-main/index.js +++ b/static/js/components/app-main/index.js @@ -129,7 +129,7 @@ module.exports = Vue.component('app-main', { xterm.focus(); xterm.startBlink(); - console.log(xterm); + //console.log(xterm); xterm.write(test); //scroll(xtermNode); diff --git a/static/js/terminal/index.js b/static/js/terminal/index.js index e8433a0..a16d3b1 100644 --- a/static/js/terminal/index.js +++ b/static/js/terminal/index.js @@ -8,13 +8,47 @@ var states = require('./lib/states'); module.exports = Terminal; -function Terminal(opts){ - opts = opts || {}; +function iterator(from, iterator, context){ + for (var key in from) { + if (from.hasOwnProperty(key)) { + iterator.call(context, key, from[key]); + } + } +} - if (!(this instanceof Terminal)) return new Terminal(opts); +function Terminal(options){ + options = options || {}; - this.cols = opts.cols || 500; - this.rows = opts.rows || 100; + if (!(this instanceof Terminal)) return new Terminal(options); + + iterator(Terminal.defaults, function (key, value){ + console.log(key); + + if (options.hasOwnProperty(options)) { + this[key] = options[key]; + } else { + this[key] = value; + } + }, this); + + if (Array.isArray(options.colors)) { + if (options.colors.length === 8) { + this.colors = options.colors.concat(Terminal.colors.slice(8)); + } else if (options.colors.length === 16) { + this.colors = options.colors.concat(Terminal.colors.slice(16)); + } else if (options.colors.length === 10) { + this.colors = options.colors.slice(0, -2).concat(Terminal.colors.slice(8, -2), options.colors.slice(-2)); + } else if (options.colors.length === 18) { + this.colors = options.colors.slice(0, -2).concat(Terminal.colors.slice(16, -2), options.colors.slice(-2)); + } else { + this.colors = Terminal.colors; + } + } else { + this.colors = Terminal.colors; + } + + this.cols = options.cols || Terminal.geometry[0]; + this.rows = options.rows || Terminal.geometry[1]; this.ybase = 0; this.ydisp = 0; diff --git a/static/js/terminal/lib/cursor.js b/static/js/terminal/lib/cursor.js index 10c6bb1..fdd752a 100644 --- a/static/js/terminal/lib/cursor.js +++ b/static/js/terminal/lib/cursor.js @@ -5,7 +5,7 @@ 'use strict'; module.exports = function (Terminal){ - Terminal.prototype.cursorBlink = function (){ + Terminal.prototype.blinkCursor = function (){ if (Terminal.focus !== this) return; this.cursorState ^= 1; @@ -20,19 +20,19 @@ module.exports = function (Terminal){ }; Terminal.prototype.startBlink = function (){ - if (!Terminal.cursorBlink) return; + if (!this.cursorBlink) return; var self = this; this._blinker = function (){ - self.cursorBlink(); + self.blinkCursor(); }; this._blink = setInterval(this._blinker, 500); }; Terminal.prototype.refreshBlink = function (){ - if (!Terminal.cursorBlink) return; + if (!this.cursorBlink) return; clearInterval(this._blink); diff --git a/static/js/terminal/lib/options.js b/static/js/terminal/lib/options.js index 1c9aef6..e5ef48b 100644 --- a/static/js/terminal/lib/options.js +++ b/static/js/terminal/lib/options.js @@ -14,4 +14,15 @@ module.exports = function (Terminal){ Terminal.screenKeys = false; Terminal.programFeatures = false; Terminal.debug = false; + + Terminal.defaults = { + termName: Terminal.termName, + cursorBlink: Terminal.cursorBlink, + visualBell: Terminal.visualBell, + popOnBell: Terminal.popOnBell, + scrollback: Terminal.scrollback, + screenKeys: Terminal.screenKeys, + programFeatures: Terminal.programFeatures, + debug: Terminal.debug + }; }; diff --git a/static/js/terminal/lib/refresh.js b/static/js/terminal/lib/refresh.js index fb8e469..0a65325 100644 --- a/static/js/terminal/lib/refresh.js +++ b/static/js/terminal/lib/refresh.js @@ -107,11 +107,11 @@ module.exports = function (Terminal){ } if (bgColor !== 256) { - out += 'background-color:' + Terminal.colors[bgColor] + ';'; + out += 'background-color:' + this.colors[bgColor] + ';'; } if (fgColor !== 257) { - out += 'color:' + Terminal.colors[fgColor] + ';'; + out += 'color:' + this.colors[fgColor] + ';'; } out += '">';