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');
|
|
|
|
var artwork = require('./art.js');
|
2015-03-19 05:08:23 +00:00
|
|
|
var moduleUtil = require('./module_util.js');
|
2014-10-31 04:59:21 +00:00
|
|
|
var Log = require('./logger.js').log;
|
|
|
|
var Config = require('./config.js').config;
|
2014-10-17 02:21:06 +00:00
|
|
|
var packageJson = require('../package.json');
|
2014-10-29 11:30:20 +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
|
|
|
|
2014-10-29 11:30:20 +00:00
|
|
|
function ansiQueryTermSizeIfNeeded(client) {
|
|
|
|
if(client.term.termHeight > 0 || client.term.termWidth > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var onCPR = function(pos) {
|
|
|
|
//
|
|
|
|
// If we've already found out, disregard
|
|
|
|
//
|
|
|
|
if(client.term.termHeight > 0 || client.term.termWidth > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-31 04:59:21 +00:00
|
|
|
assert(2 === pos.length);
|
2014-10-29 11:30:20 +00:00
|
|
|
client.term.termHeight = pos[0];
|
|
|
|
client.term.termWidth = pos[1];
|
|
|
|
|
2014-10-31 04:59:21 +00:00
|
|
|
Log.debug(
|
|
|
|
{ termWidth : client.term.termWidth, termHeight : client.term.termHeight, updateSource : 'ANSI CPR' },
|
|
|
|
'Window size updated');
|
2014-10-29 11:30:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
client.once('cursor position report', onCPR);
|
|
|
|
|
|
|
|
// give up after 2s
|
|
|
|
setTimeout(function onTimeout() {
|
|
|
|
client.removeListener('cursor position report', onCPR);
|
|
|
|
}, 2000);
|
2014-10-17 02:21:06 +00:00
|
|
|
|
2014-10-29 11:30:20 +00:00
|
|
|
client.term.write(ansi.queryScreenSize());
|
|
|
|
}
|
|
|
|
|
2014-10-31 04:59:21 +00:00
|
|
|
function prepareTerminal(term) {
|
2014-10-17 02:21:06 +00:00
|
|
|
term.write(ansi.normal());
|
|
|
|
term.write(ansi.disableVT100LineWrapping());
|
|
|
|
// :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) {
|
2014-10-17 02:21:06 +00:00
|
|
|
// :TODO: add URL to banner
|
|
|
|
term.write(ansi.fromPipeCode(util.format('' +
|
|
|
|
'|33Conected to |32EN|33|01i|32|22GMA|32|01½|00 |33BBS version|31|01 %s\n' +
|
|
|
|
'|00|33Copyright (c) 2014 Bryan Ashby\n' +
|
|
|
|
'|00', packageJson.version)));
|
2014-10-31 04:59:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function connectEntry(client) {
|
|
|
|
var term = client.term;
|
|
|
|
|
|
|
|
//
|
|
|
|
// If we don't yet know the client term width/height,
|
|
|
|
// try with a nonstandard ANSI DSR type request.
|
|
|
|
//
|
|
|
|
ansiQueryTermSizeIfNeeded(client);
|
|
|
|
|
|
|
|
prepareTerminal(term);
|
|
|
|
displayBanner(term);
|
2014-10-17 02:21:06 +00:00
|
|
|
|
|
|
|
setTimeout(function onTimeout() {
|
|
|
|
term.write(ansi.clearScreen());
|
|
|
|
|
|
|
|
artwork.getArt('CONNECT', { random : true, readSauce : true }, function onArt(err, art) {
|
|
|
|
var timeout = 0;
|
|
|
|
|
|
|
|
if(!err) {
|
|
|
|
term.write(art.data);
|
|
|
|
timeout = 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(function onTimeout() {
|
|
|
|
term.write(ansi.clearScreen());
|
2015-04-04 20:41:04 +00:00
|
|
|
|
|
|
|
client.gotoMenuModule({ name : Config.entryMod } );
|
2014-10-17 02:21:06 +00:00
|
|
|
}, timeout);
|
|
|
|
});
|
|
|
|
}, 500);
|
|
|
|
}
|
|
|
|
|