2014-10-17 02:21:06 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2014-10-31 04:59:21 +00:00
|
|
|
var ansi = require('./ansi_term.js');
|
2015-04-17 04:29:53 +00:00
|
|
|
var theme = require('./theme.js');
|
2015-03-19 05:08:23 +00:00
|
|
|
var moduleUtil = require('./module_util.js');
|
2014-10-31 04:59:21 +00:00
|
|
|
var Config = require('./config.js').config;
|
2015-06-30 19:04:58 +00:00
|
|
|
|
2014-10-31 04:59:21 +00:00
|
|
|
var assert = require('assert');
|
2014-10-17 02:21:06 +00:00
|
|
|
var util = require('util');
|
|
|
|
|
2014-10-31 04:59:21 +00:00
|
|
|
exports.connectEntry = connectEntry;
|
2014-10-17 02:21:06 +00:00
|
|
|
|
2015-05-16 05:02:58 +00:00
|
|
|
function ansiQueryTermSizeIfNeeded(client, cb) {
|
2014-10-29 11:30:20 +00:00
|
|
|
if(client.term.termHeight > 0 || client.term.termWidth > 0) {
|
2015-05-16 05:02:58 +00:00
|
|
|
cb(true);
|
2014-10-29 11:30:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-23 04:09:52 +00:00
|
|
|
var done = function(res) {
|
|
|
|
client.removeListener('cursor position report', cprListener);
|
|
|
|
clearTimeout(giveUpTimer);
|
|
|
|
cb(res);
|
|
|
|
};
|
|
|
|
|
2015-05-16 05:02:58 +00:00
|
|
|
var cprListener = function(pos) {
|
2014-10-29 11:30:20 +00:00
|
|
|
//
|
|
|
|
// If we've already found out, disregard
|
|
|
|
//
|
|
|
|
if(client.term.termHeight > 0 || client.term.termWidth > 0) {
|
2015-07-23 04:09:52 +00:00
|
|
|
done(true);
|
2014-10-29 11:30:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-31 04:59:21 +00:00
|
|
|
assert(2 === pos.length);
|
2015-05-16 05:02:58 +00:00
|
|
|
var h = pos[0];
|
|
|
|
var w = pos[1];
|
|
|
|
|
|
|
|
//
|
|
|
|
// Netrunner for example gives us 1x1 here. Not really useful. Ignore
|
|
|
|
// values that seem obviously bad.
|
|
|
|
//
|
|
|
|
if(h < 10 || w < 10) {
|
2015-07-04 21:21:50 +00:00
|
|
|
client.log.warn(
|
2015-05-16 05:02:58 +00:00
|
|
|
{ height : h, width : w },
|
|
|
|
'Ignoring ANSI CPR screen size query response due to very small values');
|
2015-07-23 04:09:52 +00:00
|
|
|
done(false);
|
2015-05-16 05:02:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
client.term.termHeight = h;
|
|
|
|
client.term.termWidth = w;
|
2014-10-29 11:30:20 +00:00
|
|
|
|
2015-07-04 21:21:50 +00:00
|
|
|
client.log.debug(
|
2015-05-16 05:02:58 +00:00
|
|
|
{
|
|
|
|
termWidth : client.term.termWidth,
|
|
|
|
termHeight : client.term.termHeight,
|
|
|
|
source : 'ANSI CPR'
|
|
|
|
},
|
|
|
|
'Window size updated'
|
|
|
|
);
|
2015-07-04 21:21:50 +00:00
|
|
|
|
2015-07-23 04:09:52 +00:00
|
|
|
done(true);
|
2014-10-29 11:30:20 +00:00
|
|
|
};
|
|
|
|
|
2015-05-16 05:02:58 +00:00
|
|
|
client.once('cursor position report', cprListener);
|
2014-10-29 11:30:20 +00:00
|
|
|
|
|
|
|
// give up after 2s
|
2015-07-23 04:09:52 +00:00
|
|
|
var giveUpTimer = setTimeout(function onTimeout() {
|
|
|
|
done(false);
|
2014-10-29 11:30:20 +00:00
|
|
|
}, 2000);
|
2014-10-17 02:21:06 +00:00
|
|
|
|
2015-07-23 04:09:52 +00:00
|
|
|
// This causes
|
2015-08-20 04:10:18 +00:00
|
|
|
client.term.rawWrite(ansi.queryScreenSize());
|
2014-10-29 11:30:20 +00:00
|
|
|
}
|
|
|
|
|
2014-10-31 04:59:21 +00:00
|
|
|
function prepareTerminal(term) {
|
2015-08-20 04:10:18 +00:00
|
|
|
term.rawWrite(ansi.normal());
|
|
|
|
term.rawWrite(ansi.disableVT100LineWrapping());
|
2014-10-17 02:21:06 +00:00
|
|
|
// :TODO: set xterm stuff -- see x84/others
|
2014-10-31 04:59:21 +00:00
|
|
|
}
|
2014-10-17 02:21:06 +00:00
|
|
|
|
2014-10-31 04:59:21 +00:00
|
|
|
function displayBanner(term) {
|
2015-05-16 05:02:58 +00:00
|
|
|
// :TODO: add URL(s) to banner
|
2015-08-27 22:14:56 +00:00
|
|
|
term.pipeWrite(
|
2015-09-11 03:01:04 +00:00
|
|
|
'|33Conected to |32EN|33|01i|00|32|22GMA|32|01½|00 |33BBS version|31|01 |VN\n' +
|
2015-08-06 22:25:52 +00:00
|
|
|
'|00|33Copyright (c) 2014-2015 Bryan Ashby |33|01- |31|01http://l33t.codes/\n' +
|
2015-09-11 03:01:04 +00:00
|
|
|
'|00');
|
2014-10-31 04:59:21 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 16:36:08 +00:00
|
|
|
function connectEntry(client, nextMenu) {
|
2014-10-31 04:59:21 +00:00
|
|
|
var term = client.term;
|
|
|
|
|
2015-07-24 04:23:44 +00:00
|
|
|
/*
|
|
|
|
theme.displayThemeArt({client : client, name : 'DM-ENIG.ANS'}, function onArt() {
|
|
|
|
return;
|
|
|
|
});
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
var iconv = require('iconv-lite');
|
|
|
|
var art1 = require('fs').readFileSync('/home/nuskooler/dev/enigma-bbs/mods/art/DM-ENIG.ANS');
|
|
|
|
console.log(typeof art1);
|
|
|
|
art1 = iconv.decode(art1, 'cp437');
|
|
|
|
console.log(typeof art1)
|
|
|
|
term.output.write(art1);
|
|
|
|
//term.output.write(require('iconv-lite').encode(art1, 'CP437'));
|
|
|
|
return;
|
|
|
|
*/
|
|
|
|
|
2015-07-04 22:03:44 +00:00
|
|
|
// :TODO: Enthral for example queries cursor position & checks if it worked. This might be good
|
|
|
|
// :TODO: How to detect e.g. if show/hide cursor can work? Probably can if CPR is avail
|
|
|
|
|
2015-07-07 04:37:11 +00:00
|
|
|
//
|
|
|
|
// Some terminal clients can be detected using a nonstandard ANSI DSR
|
|
|
|
//
|
|
|
|
term.rawWrite(ansi.queryDeviceAttributes(0));
|
|
|
|
|
|
|
|
// :TODO: PuTTY will apparently respond with "PuTTY" if a CTRL-E is sent to it
|
|
|
|
|
2014-10-31 04:59:21 +00:00
|
|
|
//
|
|
|
|
// If we don't yet know the client term width/height,
|
|
|
|
// try with a nonstandard ANSI DSR type request.
|
|
|
|
//
|
2015-05-16 05:02:58 +00:00
|
|
|
ansiQueryTermSizeIfNeeded(client, function ansiCprResult(result) {
|
|
|
|
|
|
|
|
if(!result) {
|
|
|
|
//
|
|
|
|
// We still don't have something good for term height/width.
|
|
|
|
// Default to DOS size 80x25.
|
|
|
|
//
|
|
|
|
// :TODO: Netrunner is currenting hitting this and it feels wrong. Why is NAWS/ENV/CPR all failing???
|
2015-07-04 21:21:50 +00:00
|
|
|
client.log.warn('Failed to negotiate term size; Defaulting to 80x25!');
|
2015-05-16 05:02:58 +00:00
|
|
|
|
|
|
|
term.termHeight = 25;
|
|
|
|
term.termWidth = 80;
|
|
|
|
}
|
2014-10-31 04:59:21 +00:00
|
|
|
|
2015-05-16 05:02:58 +00:00
|
|
|
prepareTerminal(term);
|
2015-04-19 08:13:13 +00:00
|
|
|
|
2015-05-16 05:02:58 +00:00
|
|
|
//
|
|
|
|
// Always show a ENiGMA½ banner
|
|
|
|
//
|
|
|
|
displayBanner(term);
|
2014-10-17 02:21:06 +00:00
|
|
|
|
2015-05-16 05:02:58 +00:00
|
|
|
setTimeout(function onTimeout() {
|
2015-10-22 16:36:08 +00:00
|
|
|
client.gotoMenuModule( { name : nextMenu } );
|
2015-05-16 05:02:58 +00:00
|
|
|
}, 500);
|
|
|
|
});
|
2014-10-17 02:21:06 +00:00
|
|
|
}
|
|
|
|
|