* Word wrap messages when output via Gopher server

* Fix Gopher startup banner default
This commit is contained in:
Bryan Ashby 2018-11-20 21:02:30 -07:00
parent 37914b8f71
commit 3af5b6f509
3 changed files with 43 additions and 7 deletions

View File

@ -17,6 +17,7 @@ const {
} = require('../../message_area.js'); } = require('../../message_area.js');
const { sortAreasOrConfs } = require('../../conf_area_util.js'); const { sortAreasOrConfs } = require('../../conf_area_util.js');
const AnsiPrep = require('../../ansi_prep.js'); const AnsiPrep = require('../../ansi_prep.js');
const { wordWrapText } = require('../../word_wrap.js');
// deps // deps
const net = require('net'); const net = require('net');
@ -27,9 +28,10 @@ const moment = require('moment');
const ModuleInfo = exports.moduleInfo = { const ModuleInfo = exports.moduleInfo = {
name : 'Gopher', name : 'Gopher',
desc : 'Gopher Server', desc : 'A RFC-1436-ish Gopher Server',
author : 'NuSkooler', author : 'NuSkooler',
packageName : 'codes.l33t.enigma.gopher.server', packageName : 'codes.l33t.enigma.gopher.server',
notes : 'https://tools.ietf.org/html/rfc1436',
}; };
const Message = require('../../message.js'); const Message = require('../../message.js');
@ -158,7 +160,7 @@ exports.getModule = class GopherModule extends ServerModule {
defaultGenerator(selectorMatch, cb) { defaultGenerator(selectorMatch, cb) {
this.log.debug( { selector : selectorMatch[0] }, 'Serving default content'); this.log.debug( { selector : selectorMatch[0] }, 'Serving default content');
let bannerFile = _.get(Config(), 'contentServers.gopher.bannerFile', 'startup_banner.asc'); let bannerFile = _.get(Config(), 'contentServers.gopher.bannerFile', 'gopher_banner.asc');
bannerFile = paths.isAbsolute(bannerFile) ? bannerFile : paths.join(__dirname, '../../../misc', bannerFile); bannerFile = paths.isAbsolute(bannerFile) ? bannerFile : paths.join(__dirname, '../../../misc', bannerFile);
fs.readFile(bannerFile, 'utf8', (err, banner) => { fs.readFile(bannerFile, 'utf8', (err, banner) => {
if(err) { if(err) {
@ -182,21 +184,43 @@ exports.getModule = class GopherModule extends ServerModule {
} }
prepareMessageBody(body, cb) { prepareMessageBody(body, cb) {
//
// From RFC-1436:
// "User display strings are intended to be displayed on a line on a
// typical screen for a user's viewing pleasure. While many screens can
// accommodate 80 character lines, some space is needed to display a tag
// of some sort to tell the user what sort of item this is. Because of
// this, the user display string should be kept under 70 characters in
// length. Clients may truncate to a length convenient to them."
//
// Messages on BBSes however, have generally been <= 79 characters. If we
// start wrapping earlier, things will generally be OK except:
// * When we're doing with FTN-style quoted lines
// * When dealing with ANSI/ASCII art
//
// Anyway, the spec says "should" and not MUST or even SHOULD! ...so, to
// to follow the KISS principle: Wrap at 79.
//
const WordWrapColumn = 79;
if(isAnsi(body)) { if(isAnsi(body)) {
AnsiPrep( AnsiPrep(
body, body,
{ {
cols : 79, // Gopher std. wants 70, but we'll have to deal with it. cols : WordWrapColumn, // See notes above
forceLineTerm : true, // ensure each line is term'd forceLineTerm : true, // Ensure each line is term'd
asciiMode : true, // export to ASCII asciiMode : true, // Export to ASCII
fillLines : false, // don't fill up to |cols| fillLines : false, // Don't fill up to |cols|
}, },
(err, prepped) => { (err, prepped) => {
return cb(prepped || body); return cb(prepped || body);
} }
); );
} else { } else {
return cb(cleanControlCodes(body, { all : true } )); const prepped = splitTextAtTerms(cleanControlCodes(body, { all : true } ) )
.map(l => (wordWrapText(l, { width : WordWrapColumn } ).wrapped || []).join('\n'))
.join('\n');
return cb(prepped);
} }
} }

View File

@ -211,6 +211,9 @@
port: XXXXX port: XXXXX
enabled: false enabled: false
// bannerFile path in misc/ by default. Full paths allowed.
bannerFile: XXXXX
// //
// The Gopher Content Server can export message base // The Gopher Content Server can export message base
// conferences and areas via the "messageConferences" key. // conferences and areas via the "messageConferences" key.

9
misc/gopher_banner.asc Normal file
View File

@ -0,0 +1,9 @@
_____________________ _____ ____________________ __________\_ /
\__ ____/\_ ____ \ /____/ / _____ __ \ / ______/ // /___jp!
// __|___// | \// |// | \// | | \// \ /___ /_____
/____ _____| __________ ___|__| ____| \ / _____ \
---- \______\ -- |______\ ------ /______/ ---- |______\ - |______\ /__/ // ___/
/__ _\
<*> ENiGMA½ // HTTPS://GITHUB.COM/NUSKOOLER/ENIGMA-BBS <*> /__/
-------------------------------------------------------------------------------