Skip to content

Commit

Permalink
move glue code into webterm.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Gottox committed Feb 8, 2016
1 parent 580ea2f commit 38b4506
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
3 changes: 3 additions & 0 deletions app.js
Expand Up @@ -19,6 +19,9 @@ server.on('request', function(req, res) {
case '/index.html':
file = '/index.html';
break;
case '/webterm.js':
file = '/webterm.js';
break;
case '/terminal.js':
file = '/node_modules/terminal.js/dist/terminal.js';
break;
Expand Down
23 changes: 1 addition & 22 deletions index.html
Expand Up @@ -17,27 +17,6 @@
</head>
<body>
<pre class="terminaljs" data-columns="80" data-rows="24"></pre>

<script>
var containers = document.getElementsByClassName('terminaljs'),
socket = io(location.origin + '/pty'), term, stream;
for(var i = 0; i < containers.length; i++) {

// setting tabindex makes the element focusable
containers[i].tabindex = 0;

// use data-* attributes to configure terminal and child_pty
term = new Terminal(containers[i].dataset);

// Create bidirectional stream
stream = ss.createStream({decodeStrings: false, encoding: 'utf-8'});

// Send stream and options to the server
ss(socket).emit('new', stream, containers[i].dataset);

// Connect everything up
stream.pipe(term).dom(containers[i]).pipe(stream);
}
</script>
<script src="/webterm.js"></script>
</body>
</html>
24 changes: 24 additions & 0 deletions webterm.js
@@ -0,0 +1,24 @@
var containers = document.getElementsByClassName('terminaljs'),
socket = io('http://127.0.0.1:3000/pty'), term, stream;
for(var i = 0; i < containers.length; i++) {

setTimeout(function(i) {
// setting tabindex makes the element focusable
containers[i].tabindex = 0;

// use data-* attributes to configure terminal and child_pty
term = new Terminal(containers[i].dataset);

// Create bidirectional stream
stream = ss.createStream({decodeStrings: false, encoding: 'utf-8'});

// Send stream and options to the server
ss(socket).emit('new', stream, containers[i].dataset);

if(containers[i].dataset.exec)
stream.write(containers[i].dataset.exec + "\n");

// Connect everything up
stream.pipe(term).dom(containers[i]).pipe(stream);
}.bind(null, i), i*1000);
}

0 comments on commit 38b4506

Please sign in to comment.