refactor and improve blessed-telnet.
This commit is contained in:
parent
29c9d1529a
commit
802e4ddc48
|
@ -11,6 +11,7 @@
|
|||
process.title = 'blessed-telnet';
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var blessed = require('blessed');
|
||||
var telnet = require('telnet');
|
||||
|
||||
|
@ -25,15 +26,12 @@ var server = telnet.createServer(function(client) {
|
|||
client.do.environment_variables();
|
||||
|
||||
client.on('environment variables', function(data) {
|
||||
if (data.command === 'sb') {
|
||||
if (data.name === 'TERM') {
|
||||
if (data.command === 'sb' && data.name === 'TERM') {
|
||||
screen.terminal = data.value;
|
||||
screen.render();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// XXX For when termtype is implemented in node-telnet
|
||||
client.on('terminal type', function(data) {
|
||||
if (data.command === 'sb' && data.name) {
|
||||
screen.terminal = data.name;
|
||||
|
@ -81,10 +79,6 @@ var server = telnet.createServer(function(client) {
|
|||
}
|
||||
});
|
||||
|
||||
screen.key(['C-c', 'q'], function(ch, key) {
|
||||
screen.destroy();
|
||||
});
|
||||
|
||||
screen.on('destroy', function() {
|
||||
if (client.writable) {
|
||||
client.destroy();
|
||||
|
@ -115,28 +109,24 @@ function simpleTest(screen) {
|
|||
screen.render();
|
||||
});
|
||||
|
||||
screen.key(['C-c', 'q'], function(ch, key) {
|
||||
screen.destroy();
|
||||
});
|
||||
|
||||
screen.render();
|
||||
}
|
||||
|
||||
var test = 'widget-' + (process.argv[2] || 'shadow');
|
||||
if (test === 'widget-png') process.argv.length = 2;
|
||||
var test = process.argv[2] || '../test/widget-shadow.js';
|
||||
if (~test.indexOf('widget-png.js')) process.argv.length = 2;
|
||||
test = path.resolve(process.cwd(), test);
|
||||
|
||||
function loadTest(screen, name) {
|
||||
var Screen = blessed.screen;
|
||||
var key = screen.key;
|
||||
blessed.screen = function() { return screen; };
|
||||
screen.key = function(keys) {
|
||||
keys = [].concat(keys)
|
||||
if (~keys.indexOf('q') || ~keys.indexOf('C-c') || ~keys.indexOf('escape')) {
|
||||
return;
|
||||
}
|
||||
return key.apply(screen, arguments);
|
||||
};
|
||||
var path = require.resolve('../test/' + name);
|
||||
var path = require.resolve(name);
|
||||
delete require.cache[path];
|
||||
require('../test/' + name);
|
||||
require(name);
|
||||
blessed.screen = Screen;
|
||||
screen.key = key;
|
||||
}
|
||||
|
||||
server.listen(2300);
|
||||
|
|
Loading…
Reference in New Issue