This commit is contained in:
Christopher Jeffrey
2013-08-08 09:03:31 -05:00
commit 51946a73c8
9 changed files with 168 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
node_modules/
*.swp
build/*
.lock-wscript
out/
Makefile.gyp
*.Makefile
*.target.gyp.mk
*.node
+19
View File
@@ -0,0 +1,19 @@
Copyright (c) 2012-2013, Christopher Jeffrey (https://github.com/chjj/)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+10
View File
@@ -0,0 +1,10 @@
# term.js
A terminal written in javascript. Used by
[tty.js](https://github.com/chjj/tty.js).
## License
Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
[1]: http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking
+1
View File
@@ -0,0 +1 @@
module.exports = require('./lib/term.js');
+14
View File
@@ -0,0 +1,14 @@
{
"name": "term.js",
"description": "A terminal written in javascript",
"author": "Christopher Jeffrey",
"version": "0.0.1",
"main": "./index.js",
"preferGlobal": false,
"repository": "git://github.com/chjj/term.js.git",
"homepage": "https://github.com/chjj/term.js",
"bugs": { "url": "https://github.com/chjj/term.js/issues" },
"keywords": ["tty", "terminal", "term"],
"tags": ["tty", "terminal", "term"],
"engines": { "node": ">= 0.8.0" }
}
+36
View File
@@ -0,0 +1,36 @@
var element = {
createElement: function() { return element; },
appendChild: function() {},
removeChild: function() {},
addEventListener: function() {},
removeEventListener: function() {},
style: {}
};
global.window = global;
window.navigator = { userAgent: '' };
window.document = element;
window.document.body = element;
var Terminal = require('../static/term');
Terminal.cursorBlink = false;
var data = require('./data').data;
var term = new Terminal(250, 100);
term.open();
var time = new Date;
var t = 10;
while (t--) {
var l = data.length
, i = 0;
for (; i < l; i++) {
term.write(data[i]);
}
}
console.log('Completed: %d.', new Date - time);
console.log('Average (?): 13.5k (for ~2.7k writes).');
+10
View File
@@ -0,0 +1,10 @@
167a168,170
> var stream = fs.createWriteStream(__dirname + '/../test/data.js');
> stream.write('this.data = [\n');
>
169a173
> stream.write(' ' + JSON.stringify(data) + ',\n');
182a187,189
>
> stream.write('];\n');
> stream.end();
+44
View File
@@ -0,0 +1,44 @@
<!doctype html>
<title>tty.js test</title>
<link rel="stylesheet" href="style.css">
<style>
body > div { float: left; }
h1 { margin-bottom: 20px; }
</style>
<h1>tty.js test</h1>
<script src="term.js"></script>
<script src="data.js"></script>
<script>
;(function() {
var time = new Date
, l = data.length * 0.9 | 0
, i = 0;
Terminal.cursorBlink = false;
var term = new Terminal(80, 30);
setTimeout(function() {
// Add terminal.
term.open();
// Run benchmark.
(function write() {
if (i >= l) return next();
term.write(data[i]);
i++;
setTimeout(write, 1);
})();
// Results.
function next() {
term.write('\x1b[2J');
term.reset();
term.refresh(0, term.rows - 1);
term.writeln('Completed in ' + (new Date - time) + '.');
term.writeln('Writes: ' + l + '.');
term.writeln('Average (?): 28.5k (for ~2.5k writes).');
}
}, 500);
}).call(this);
</script>
+25
View File
@@ -0,0 +1,25 @@
var path = require('path')
, fs = require('fs');
var express = require('express')
, app = express.createServer();
app.use(function(req, res, next) {
var setHeader = res.setHeader;
res.setHeader = function(name) {
switch (name) {
case 'Cache-Control':
case 'Last-Modified':
case 'ETag':
return;
}
return setHeader.apply(res, arguments);
};
next();
});
app.use(express.static(__dirname));
app.use(express.static(__dirname + '/../static'));
app.listen(8080);