deal with bad csr's. improve example. readme.

This commit is contained in:
Christopher Jeffrey
2013-08-10 15:39:28 -05:00
parent 49d3a20f3c
commit 628af0532f
4 changed files with 77 additions and 44 deletions
+19 -10
View File
@@ -1,7 +1,7 @@
<!doctype html>
<title>tty.js</title>
<title>term.js</title>
<!--
tty.js
term.js
Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
-->
<style>
@@ -19,21 +19,24 @@
background: #000;
}
.reverse-video {
.terminal-cursor {
color: #000;
background: #f0f0f0;
}
</style>
<h1>tty.js</h1>
<h1>term.js</h1>
<script src="/socket.io/socket.io.js"></script>
<script src="term.js"></script>
<script>
;(function() {
return setTimeout(function() {
var term = new Terminal(80, 24)
, socket = io.connect();
window.onload = function() {
var socket = io.connect();
socket.on('connect', function() {
var term = new Terminal({
cols: 80,
rows: 24
});
term.on('data', function(data) {
socket.emit('data', data);
});
@@ -42,12 +45,18 @@
document.title = title;
});
term.open();
term.open(document.body);
term.write('\x1b[31mWelcome to term.js!\x1b[m\r\n');
socket.on('data', function(data) {
term.write(data);
});
socket.on('disconnect', function() {
term.destroy();
});
});
}, 1000);
};
}).call(this);
</script>
+20 -11
View File
@@ -1,18 +1,19 @@
/**
* tty.js
* term.js
* Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
*/
var http = require('http')
, express = require('express')
, io = require('socket.io')
, pty = require('pty.js');
, pty = require('pty.js')
, terminal = require('../');
/**
* tty.js
* term.js
*/
process.title = 'tty.js';
process.title = 'term.js';
/**
* Open Terminal
@@ -22,8 +23,10 @@ var buff = []
, socket
, term;
var term = pty.fork(process.env.SHELL || 'sh', [], {
name: 'xterm',
term = pty.fork(process.env.SHELL || 'sh', [], {
name: require('fs').existsSync('/usr/share/terminfo/x/xterm-256color')
? 'xterm-256color'
: 'xterm',
cols: 80,
rows: 24,
cwd: process.env.HOME
@@ -61,8 +64,15 @@ app.use(function(req, res, next) {
next();
});
app.use(express.basicAuth(function(user, pass, next) {
if (user !== 'foo' || pass !== 'bar') {
return next(true);
}
return next(null, user);
}));
app.use(express.static(__dirname));
app.use(express.static(__dirname + '/../lib'));
app.use(terminal.middleware());
server.listen(8080);
@@ -74,6 +84,7 @@ server.on('connection', function(socket) {
} catch (e) {
;
}
console.log('Attempted connection from %s. Refused.', address);
}
});
@@ -81,10 +92,8 @@ server.on('connection', function(socket) {
* Sockets
*/
io = io.listen(server);
io.configure(function() {
io.disable('log');
io = io.listen(server, {
log: false
});
io.sockets.on('connection', function(sock) {