Skip to content

Commit

Permalink
refactor and improve blessed-telnet.
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Aug 8, 2015
1 parent 29c9d15 commit 802e4dd
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions example/blessed-telnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
process.title = 'blessed-telnet';

var fs = require('fs');
var path = require('path');
var blessed = require('blessed');
var telnet = require('telnet');

Expand All @@ -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') {
screen.terminal = data.value;
screen.render();
}
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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 802e4dd

Please sign in to comment.