mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
deal with bad csr's. improve example. readme.
This commit is contained in:
@@ -9,7 +9,7 @@ Server:
|
||||
|
||||
``` js
|
||||
var term = require('term.js');
|
||||
express.use(term.middleware());
|
||||
app.use(term.middleware());
|
||||
...
|
||||
```
|
||||
|
||||
@@ -17,22 +17,33 @@ Client:
|
||||
|
||||
``` js
|
||||
window.addEventListener('load', function() {
|
||||
var term = new Terminal({
|
||||
cols: 80,
|
||||
rows: 24
|
||||
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);
|
||||
});
|
||||
|
||||
term.on('title', function(title) {
|
||||
document.title = title;
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
||||
term.open(document.body);
|
||||
|
||||
term.on('data', function(data) {
|
||||
console.log(data);
|
||||
});
|
||||
|
||||
term.on('title', function(title) {
|
||||
console.log('New title: ' + title);
|
||||
});
|
||||
|
||||
term.write('\x1b[41hello world\x1b[m');
|
||||
}, false);
|
||||
```
|
||||
|
||||
|
||||
+19
-10
@@ -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
@@ -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) {
|
||||
|
||||
+11
-7
@@ -822,9 +822,9 @@ Terminal.prototype.bindMouse = function() {
|
||||
// be sure to avoid sending
|
||||
// bad positions to the program
|
||||
if (x < 0) x = 0;
|
||||
if (x >= self.cols) x = self.cols - 1;
|
||||
if (x > self.cols) x = self.cols;
|
||||
if (y < 0) y = 0;
|
||||
if (y >= self.rows) y = self.rows - 1;
|
||||
if (y > self.rows) y = self.rows;
|
||||
|
||||
// xterm sends raw bytes and
|
||||
// starts at 32 (SP) for each.
|
||||
@@ -909,6 +909,9 @@ Terminal.prototype.destroy = function() {
|
||||
this._events = {};
|
||||
this.handler = function() {};
|
||||
this.write = function() {};
|
||||
if (this.element.parentNode) {
|
||||
this.element.parentNode.removeChild(this.element);
|
||||
}
|
||||
//this.emit('close');
|
||||
};
|
||||
|
||||
@@ -950,9 +953,10 @@ Terminal.prototype.refresh = function(start, end) {
|
||||
width = this.cols;
|
||||
y = start;
|
||||
|
||||
// if (end > this.lines.length) {
|
||||
// end = this.lines.length;
|
||||
// }
|
||||
if (end >= this.lines.length) {
|
||||
this.log('`end` is too large. Most likely a bad CSR.');
|
||||
end = this.lines.length - 1;
|
||||
}
|
||||
|
||||
for (; y <= end; y++) {
|
||||
row = y + this.ydisp;
|
||||
@@ -984,7 +988,7 @@ Terminal.prototype.refresh = function(start, end) {
|
||||
}
|
||||
if (data !== this.defAttr) {
|
||||
if (data === -1) {
|
||||
out += '<span class="reverse-video">';
|
||||
out += '<span class="reverse-video terminal-cursor">';
|
||||
} else {
|
||||
out += '<span style="';
|
||||
|
||||
@@ -996,7 +1000,7 @@ Terminal.prototype.refresh = function(start, end) {
|
||||
if (!Terminal.brokenBold) {
|
||||
out += 'font-weight:bold;';
|
||||
}
|
||||
// see: XTerm*boldColors
|
||||
// See: XTerm*boldColors
|
||||
if (fgColor < 8) fgColor += 8;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user