* Explicit encoding handling

* Word wrap with ANSI in FSE
This commit is contained in:
Bryan Ashby 2017-08-20 20:42:25 -06:00
parent b3ce44ae42
commit 2b83630431
2 changed files with 46 additions and 15 deletions

View File

@ -14,6 +14,7 @@ const StatLog = require('./stat_log.js');
const stringFormat = require('./string_format.js');
const MessageAreaConfTempSwitcher = require('./mod_mixins.js').MessageAreaConfTempSwitcher;
const { isAnsi, cleanControlCodes } = require('./string_util.js');
const Config = require('./config.js').config;
// deps
const async = require('async');
@ -324,7 +325,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
toUserName : headerValues.to,
fromUserName : this.client.user.username,
subject : headerValues.subject,
message : this.viewControllers.body.getFormData().value.message,
message : this.viewControllers.body.getFormData().value.message,
};
if(this.isReply()) {
@ -333,9 +334,12 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
if(this.replyIsAnsi) {
//
// Ensure first characters indicate ANSI for detection down
// the line (other boards/etc.)
// the line (other boards/etc.). We also set explicit_encoding
// to packetAnsiMsgEncoding (generally cp437) as various boards
// really don't like ANSI messages in UTF-8 encoding (they should!)
//
msgOpts.message = `${ansi.normal()}${msgOpts.message}`;
msgOpts.meta = { System : { 'explicit_encoding' : Config.scannerTossers.ftn_bso.packetAnsiMsgEncoding || 'cp437' } };
msgOpts.message = `${ansi.reset()}${ansi.eraseData(2)}${ansi.goto(1,1)}${msgOpts.message}`;
}
}
@ -363,8 +367,9 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
bodyMessageView.setAnsi(
this.message.message.replace(/\r?\n/g, '\r\n'), // messages are stored with CRLF -> LF
{
prepped : false,
forceLineTerm : true
prepped : false,
forceLineTerm : true,
preserveTextLines : this.message.replyToMsgId ? true : false,
}
);
} else {
@ -973,8 +978,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
var quoteLines = quoteMsgView.getData();
if(quoteLines.trim().length > 0) {
msgView.addText(quoteMsgView.getData() + '\n');
msgView.addText(quoteMsgView.getData() + '\n');
}
quoteMsgView.setText('');

View File

@ -511,12 +511,14 @@ function MultiLineEditTextView(options) {
}
return wordWrapText(
s, {
s,
{
width : width,
tabHandling : tabHandling || 'expand',
tabWidth : self.tabWidth,
tabChar : '\t',
});
}
);
};
this.setTextLines = function(lines, index, termWithEol) {
@ -551,7 +553,31 @@ function MultiLineEditTextView(options) {
this.setAnsiWithOptions = function(ansi, options, cb) {
function setLines(text) {
/*
self.setTextLines( strUtil.splitTextAtTerms(text), 0 );
self.cursorStartOfDocument();
*/
text = strUtil.splitTextAtTerms(text);
let index = 0;
let wrapped;
text.forEach(line => {
if(strUtil.isAnsiLine(line)) {
self.setTextLines( [ line ], index, true); // true=termWithEol
index += 1;
} else {
wrapped = self.wordWrapSingleLine(
line, // line to wrap
'expand', // tabHandling
self.dimens.width
).wrapped;
self.setTextLines(wrapped, index, true); // true=termWithEol
index += wrapped.length;
}
});
self.cursorStartOfDocument();
if(cb) {
@ -566,12 +592,13 @@ function MultiLineEditTextView(options) {
strUtil.prepAnsi(
ansi,
{
termWidth : this.client.termWidth,
termHeight : this.client.termHeight,
cols : this.dimens.width,
rows : 'auto',
startCol : this.position.col,
forceLineTerm : options.forceLineTerm,
termWidth : this.client.termWidth,
termHeight : this.client.termHeight,
cols : this.dimens.width,
rows : 'auto',
startCol : this.position.col,
forceLineTerm : options.forceLineTerm,
preserveTextLines : options.preserveTextLines,
},
(err, preppedAnsi) => {
return setLines(err ? ansi : preppedAnsi);