improve focus behavior.

This commit is contained in:
Christopher Jeffrey
2013-08-08 09:06:16 -05:00
parent 9127316158
commit 6cc8b3cd8a
5 changed files with 274 additions and 11 deletions
+53
View File
@@ -0,0 +1,53 @@
<!doctype html>
<title>tty.js</title>
<!--
tty.js
Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
-->
<style>
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;
}
.reverse-video {
color: #000;
background: #f0f0f0;
}
</style>
<h1>tty.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();
socket.on('connect', function() {
term.on('data', function(data) {
socket.emit('data', data);
});
term.on('title', function(title) {
document.title = title;
});
term.open();
socket.on('data', function(data) {
term.write(data);
});
});
}, 1000);
}).call(this);
</script>
+93
View File
@@ -0,0 +1,93 @@
/**
* tty.js
* Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
*/
var http = require('http')
, express = require('express')
, io = require('socket.io')
, pty = require('pty.js');
/**
* tty.js
*/
process.title = 'tty.js';
/**
* Open Terminal
*/
var buff = []
, socket
, term;
var term = pty.fork(process.env.SHELL || 'sh', [], {
name: 'xterm',
cols: 80,
rows: 24,
cwd: process.env.HOME
});
term.on('data', function(data) {
return !socket
? buff.push(data)
: socket.emit('data', data);
});
console.log(''
+ 'Created shell with pty master/slave'
+ ' pair (master: %d, pid: %d)',
term.fd, term.pid);
/**
* App & Server
*/
var app = express()
, server = http.createServer(app);
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 + '/../lib'));
server.listen(8080);
/**
* Sockets
*/
io = io.listen(server);
io.configure(function() {
io.disable('log');
});
io.sockets.on('connection', function(sock) {
socket = sock;
socket.on('data', function(data) {
term.write(data);
});
socket.on('disconnect', function() {
socket = null;
});
while (buff.length) {
socket.emit('data', buff.shift());
}
});