fix benchmark.

This commit is contained in:
Christopher Jeffrey
2013-08-11 05:30:04 -05:00
parent 15f6833598
commit 791127bc88
4 changed files with 64 additions and 23 deletions
+8 -6
View File
@@ -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;
+16 -3
View File
@@ -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;
+27 -9
View File
@@ -1,11 +1,26 @@
<!doctype html>
<title>tty.js test</title>
<link rel="stylesheet" href="style.css">
<title>term.js test</title>
<style>
body > div { float: left; }
h1 { margin-bottom: 20px; }
h1 {
margin-bottom: 20px;
font: 20px/1.5 sans-serif;
}
.terminal {
float: left;
border: #000 solid 5px;
font-family: "DejaVu Sans Mono", "Liberation Mono", monospace;
font-size: 11px;
color: #f0f0f0;
background: #000;
}
.terminal-cursor {
color: #000;
background: #f0f0f0;
}
</style>
<h1>tty.js test</h1>
<h1>term.js test</h1>
<script src="term.js"></script>
<script src="data.js"></script>
<script>
@@ -16,11 +31,14 @@
Terminal.cursorBlink = false;
var term = new Terminal(80, 30);
var term = new Terminal({
cols: 80,
rows: 30
});
setTimeout(function() {
window.onload = function() {
// Add terminal.
term.open();
term.open(document.body);
// Run benchmark.
(function write() {
@@ -39,6 +57,6 @@
term.writeln('Writes: ' + l + '.');
term.writeln('Average (?): 28.5k (for ~2.5k writes).');
}
}, 500);
};
}).call(this);
</script>
+13 -5
View File
@@ -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);