* Various code cleanup
* Fix term size fallback bug exposed with rxvt/telnet * Fix bug in term env request
This commit is contained in:
parent
13d104c840
commit
9715d31ac2
|
@ -330,7 +330,7 @@ function Client(input, output) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(key || ch) {
|
if(key || ch) {
|
||||||
self.log.trace( { key : key, ch : ch }, 'User keyboard input');
|
self.log.trace( { key : key, ch : escape(ch) }, 'User keyboard input');
|
||||||
|
|
||||||
self.emit('key press', ch, key);
|
self.emit('key press', ch, key);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ var ansi = require('./ansi_term.js');
|
||||||
var colorCodes = require('./color_codes.js');
|
var colorCodes = require('./color_codes.js');
|
||||||
var theme = require('./theme.js');
|
var theme = require('./theme.js');
|
||||||
var moduleUtil = require('./module_util.js');
|
var moduleUtil = require('./module_util.js');
|
||||||
var Log = require('./logger.js').log;
|
//var Log = require('./logger.js').log;
|
||||||
var Config = require('./config.js').config;
|
var Config = require('./config.js').config;
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ function ansiQueryTermSizeIfNeeded(client, cb) {
|
||||||
// values that seem obviously bad.
|
// values that seem obviously bad.
|
||||||
//
|
//
|
||||||
if(h < 10 || w < 10) {
|
if(h < 10 || w < 10) {
|
||||||
Log.warn(
|
client.log.warn(
|
||||||
{ height : h, width : w },
|
{ height : h, width : w },
|
||||||
'Ignoring ANSI CPR screen size query response due to very small values');
|
'Ignoring ANSI CPR screen size query response due to very small values');
|
||||||
cb(false);
|
cb(false);
|
||||||
|
@ -50,7 +50,7 @@ function ansiQueryTermSizeIfNeeded(client, cb) {
|
||||||
client.term.termHeight = h;
|
client.term.termHeight = h;
|
||||||
client.term.termWidth = w;
|
client.term.termWidth = w;
|
||||||
|
|
||||||
Log.debug(
|
client.log.debug(
|
||||||
{
|
{
|
||||||
termWidth : client.term.termWidth,
|
termWidth : client.term.termWidth,
|
||||||
termHeight : client.term.termHeight,
|
termHeight : client.term.termHeight,
|
||||||
|
@ -58,6 +58,8 @@ function ansiQueryTermSizeIfNeeded(client, cb) {
|
||||||
},
|
},
|
||||||
'Window size updated'
|
'Window size updated'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
cb(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
client.once('cursor position report', cprListener);
|
client.once('cursor position report', cprListener);
|
||||||
|
@ -65,7 +67,7 @@ function ansiQueryTermSizeIfNeeded(client, cb) {
|
||||||
// give up after 2s
|
// give up after 2s
|
||||||
setTimeout(function onTimeout() {
|
setTimeout(function onTimeout() {
|
||||||
client.removeListener('cursor position report', cprListener);
|
client.removeListener('cursor position report', cprListener);
|
||||||
cb(true);
|
cb(false);
|
||||||
}, 2000);
|
}, 2000);
|
||||||
|
|
||||||
client.term.write(ansi.queryScreenSize());
|
client.term.write(ansi.queryScreenSize());
|
||||||
|
@ -79,7 +81,6 @@ function prepareTerminal(term) {
|
||||||
|
|
||||||
function displayBanner(term) {
|
function displayBanner(term) {
|
||||||
// :TODO: add URL(s) to banner
|
// :TODO: add URL(s) to banner
|
||||||
//term.write(ansi.fromPipeCode(util.format('' +
|
|
||||||
term.write(colorCodes.pipeToAnsi(util.format(
|
term.write(colorCodes.pipeToAnsi(util.format(
|
||||||
'|33Conected to |32EN|33|01i|00|32|22GMA|32|01½|00 |33BBS version|31|01 %s\n' +
|
'|33Conected to |32EN|33|01i|00|32|22GMA|32|01½|00 |33BBS version|31|01 %s\n' +
|
||||||
'|00|33Copyright (c) 2014-2015 Bryan Ashby\n' +
|
'|00|33Copyright (c) 2014-2015 Bryan Ashby\n' +
|
||||||
|
@ -101,7 +102,7 @@ function connectEntry(client) {
|
||||||
// Default to DOS size 80x25.
|
// Default to DOS size 80x25.
|
||||||
//
|
//
|
||||||
// :TODO: Netrunner is currenting hitting this and it feels wrong. Why is NAWS/ENV/CPR all failing???
|
// :TODO: Netrunner is currenting hitting this and it feels wrong. Why is NAWS/ENV/CPR all failing???
|
||||||
Log.warn('Failed to negotiate term size; Defaulting to 80x25!');
|
client.log.warn('Failed to negotiate term size; Defaulting to 80x25!');
|
||||||
|
|
||||||
term.termHeight = 25;
|
term.termHeight = 25;
|
||||||
term.termWidth = 80;
|
term.termWidth = 80;
|
||||||
|
|
|
@ -586,6 +586,8 @@ TelnetClient.prototype.handleSbCommand = function(evt) {
|
||||||
'Environment variable already exists');
|
'Environment variable already exists');
|
||||||
} else {
|
} else {
|
||||||
self.term.env[name] = evt.envVars[name];
|
self.term.env[name] = evt.envVars[name];
|
||||||
|
Log.debug(
|
||||||
|
{ varName : name, value : evt.envVars[name] }, 'New environment variable');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -599,11 +601,11 @@ TelnetClient.prototype.handleSbCommand = function(evt) {
|
||||||
self.term.termHeight = evt.height;
|
self.term.termHeight = evt.height;
|
||||||
|
|
||||||
if(evt.width > 0) {
|
if(evt.width > 0) {
|
||||||
self.term.env['COLUMNS'] = evt.height;
|
self.term.env.COLUMNS = evt.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(evt.height > 0) {
|
if(evt.height > 0) {
|
||||||
self.term.env['ROWS'] = evt.height;
|
self.term.env.ROWS = evt.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.debug({ termWidth : evt.width , termHeight : evt.height, source : 'NAWS' }, 'Window size updated');
|
Log.debug({ termWidth : evt.width , termHeight : evt.height, source : 'NAWS' }, 'Window size updated');
|
||||||
|
@ -640,21 +642,17 @@ TelnetClient.prototype.handleMiscCommand = function(evt) {
|
||||||
};
|
};
|
||||||
|
|
||||||
TelnetClient.prototype.requestTerminalType = function() {
|
TelnetClient.prototype.requestTerminalType = function() {
|
||||||
var buf = Buffer([ COMMANDS.IAC, COMMANDS.SB, OPTIONS.TERMINAL_TYPE, SB_COMMANDS.SEND, COMMANDS.IAC, COMMANDS.SE ]);
|
var buf = new Buffer( [
|
||||||
/*
|
COMMANDS.IAC,
|
||||||
var buf = Buffer(6);
|
COMMANDS.SB,
|
||||||
buf[0] = COMMANDS.IAC;
|
OPTIONS.TERMINAL_TYPE,
|
||||||
buf[1] = COMMANDS.SB;
|
SB_COMMANDS.SEND,
|
||||||
buf[2] = OPTIONS.TERMINAL_TYPE;
|
COMMANDS.IAC,
|
||||||
buf[3] = SB_COMMANDS.SEND;
|
COMMANDS.SE ]);
|
||||||
buf[4] = COMMANDS.IAC;
|
|
||||||
buf[5] = COMMANDS.SE;
|
|
||||||
*/
|
|
||||||
|
|
||||||
return this.output.write(buf);
|
return this.output.write(buf);
|
||||||
};
|
};
|
||||||
|
|
||||||
var WANTED_ENVIRONMENT_VARIABLES = [ 'LINES', 'COLUMNS', 'TERM' ];
|
var WANTED_ENVIRONMENT_VARIABLES = [ 'LINES', 'COLUMNS', 'TERM', 'TERM_PROGRAM' ];
|
||||||
|
|
||||||
TelnetClient.prototype.requestEnvironmentVariables = function() {
|
TelnetClient.prototype.requestEnvironmentVariables = function() {
|
||||||
var bufs = buffers();
|
var bufs = buffers();
|
||||||
|
@ -662,7 +660,8 @@ TelnetClient.prototype.requestEnvironmentVariables = function() {
|
||||||
bufs.push(new Buffer([ COMMANDS.IAC, COMMANDS.SB, OPTIONS.NEW_ENVIRONMENT, SB_COMMANDS.SEND ]));
|
bufs.push(new Buffer([ COMMANDS.IAC, COMMANDS.SB, OPTIONS.NEW_ENVIRONMENT, SB_COMMANDS.SEND ]));
|
||||||
|
|
||||||
for(var i = 0; i < WANTED_ENVIRONMENT_VARIABLES.length; ++i) {
|
for(var i = 0; i < WANTED_ENVIRONMENT_VARIABLES.length; ++i) {
|
||||||
bufs.push(new Buffer( [ ENVIRONMENT_VARIABLES_COMMANDS.VAR ]));
|
//bufs.push(new Buffer( [ ENVIRONMENT_VARIABLES_COMMANDS.VAR ]));
|
||||||
|
bufs.push(new Buffer( [ NEW_ENVIRONMENT_COMMANDS.VAR ] ));
|
||||||
bufs.push(new Buffer(WANTED_ENVIRONMENT_VARIABLES[i])); // :TODO: encoding here?! UTF-8 will work, but shoudl be more explicit
|
bufs.push(new Buffer(WANTED_ENVIRONMENT_VARIABLES[i])); // :TODO: encoding here?! UTF-8 will work, but shoudl be more explicit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -688,19 +687,19 @@ TelnetClient.prototype.banner = function() {
|
||||||
|
|
||||||
this.do.window_size();
|
this.do.window_size();
|
||||||
this.do.new_environment();
|
this.do.new_environment();
|
||||||
}
|
};
|
||||||
|
|
||||||
function Command(command, client) {
|
function Command(command, client) {
|
||||||
this.command = COMMANDS[command.toUpperCase()];
|
this.command = COMMANDS[command.toUpperCase()];
|
||||||
this.client = client;
|
this.client = client;
|
||||||
};
|
}
|
||||||
|
|
||||||
// Create Command objects with echo, transmit_binary, ...
|
// Create Command objects with echo, transmit_binary, ...
|
||||||
Object.keys(OPTIONS).forEach(function(name) {
|
Object.keys(OPTIONS).forEach(function(name) {
|
||||||
var code = OPTIONS[name];
|
var code = OPTIONS[name];
|
||||||
|
|
||||||
Command.prototype[name.toLowerCase()] = function() {
|
Command.prototype[name.toLowerCase()] = function() {
|
||||||
var buf = Buffer(3);
|
var buf = new Buffer(3);
|
||||||
buf[0] = COMMANDS.IAC;
|
buf[0] = COMMANDS.IAC;
|
||||||
buf[1] = this.command;
|
buf[1] = this.command;
|
||||||
buf[2] = code;
|
buf[2] = code;
|
||||||
|
|
Loading…
Reference in New Issue