From 791127bc887a0ccf28e57085c3569900031faa45 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 11 Aug 2013 05:16:44 -0500 Subject: [PATCH] fix benchmark. --- lib/term.js | 14 ++++++++------ test/bench.js | 19 ++++++++++++++++--- test/index.html | 36 +++++++++++++++++++++++++++--------- test/index.js | 18 +++++++++++++----- 4 files changed, 64 insertions(+), 23 deletions(-) diff --git a/lib/term.js b/lib/term.js index 4149db29..953287ce 100644 --- a/lib/term.js +++ b/lib/term.js @@ -525,7 +525,7 @@ Terminal.prototype.open = function(parent) { : null; // Does IE9 do this? - if (~navigator.userAgent.indexOf('MSIE')) { + if (self.isMSIE) { button = button === 1 ? 0 : button === 4 ? 1 : button; } @@ -559,6 +559,11 @@ Terminal.prototype.open = function(parent) { this.element.style.backgroundColor = Terminal.defaultColors.bg; this.element.style.color = Terminal.defaultColors.fg; + if (this.context.navigator && this.context.navigator.userAgent) { + this.isMac = !!~this.context.navigator.userAgent.indexOf('Mac'); + this.isMSIE = !!~this.context.navigator.userAgent.indexOf('MSIE'); + } + // this.emit('open'); }; @@ -753,7 +758,7 @@ Terminal.prototype.bindMouse = function() { ? ev.which - 1 : null; - if (~navigator.userAgent.indexOf('MSIE')) { + if (self.isMSIE) { button = button === 1 ? 0 : button === 4 ? 1 : button; } break; @@ -2343,7 +2348,7 @@ Terminal.prototype.keyDown = function(ev) { // ^] - group sep key = String.fromCharCode(29); } - } else if ((!isMac && ev.altKey) || (isMac && ev.metaKey)) { + } else if ((!this.isMac && ev.altKey) || (this.isMac && ev.metaKey)) { if (ev.keyCode >= 65 && ev.keyCode <= 90) { key = '\x1b' + String.fromCharCode(ev.keyCode + 32); } else if (ev.keyCode === 192) { @@ -4417,8 +4422,6 @@ function inherits(child, parent) { child.prototype = new f; } -var isMac = ~navigator.userAgent.indexOf('Mac'); - // if bold is broken, we can't // use it in the terminal. function isBoldBroken(document) { @@ -4506,7 +4509,6 @@ matchColor.distance = function(r1, g1, b1, r2, g2, b2) { */ Terminal.EventEmitter = EventEmitter; -Terminal.isMac = isMac; Terminal.inherits = inherits; Terminal.on = on; Terminal.off = off; diff --git a/test/bench.js b/test/bench.js index ec6e99f8..d5de0c95 100644 --- a/test/bench.js +++ b/test/bench.js @@ -1,9 +1,15 @@ +/** + * term.js + * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License) + */ + var element = { createElement: function() { return element; }, appendChild: function() {}, removeChild: function() {}, addEventListener: function() {}, removeEventListener: function() {}, + setAttribute: function() {}, style: {} }; @@ -12,13 +18,20 @@ window.navigator = { userAgent: '' }; window.document = element; window.document.body = element; -var Terminal = require('../static/term'); +element.ownerDocument = window.document; +window.document.defaultView = window; + +var Terminal = require('../lib/term'); Terminal.cursorBlink = false; var data = require('./data').data; -var term = new Terminal(250, 100); -term.open(); +var term = new Terminal({ + cols: 250, + rows: 100 +}); + +term.open(element); var time = new Date; var t = 10; diff --git a/test/index.html b/test/index.html index a7b93dda..ab8c90d5 100644 --- a/test/index.html +++ b/test/index.html @@ -1,11 +1,26 @@ -tty.js test - +term.js test -

tty.js test

+

term.js test

diff --git a/test/index.js b/test/index.js index 42dc16c5..d798195e 100644 --- a/test/index.js +++ b/test/index.js @@ -1,8 +1,17 @@ -var path = require('path') +/** + * term.js + * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License) + */ + +var http = require('http') + , path = require('path') , fs = require('fs'); var express = require('express') - , app = express.createServer(); + , term = require('../'); + +var app = express() + , server = http.createServer(app); app.use(function(req, res, next) { var setHeader = res.setHeader; @@ -19,7 +28,6 @@ app.use(function(req, res, next) { }); app.use(express.static(__dirname)); +app.use(term.middleware()); -app.use(express.static(__dirname + '/../lib')); - -app.listen(8080); +server.listen(8080);