mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-07 13:15:28 +02:00
Fix word wrap crash reported by user when pipe codes are in play
This commit is contained in:
parent
7a6188bba0
commit
0a486d290f
2 changed files with 14 additions and 5 deletions
|
@ -218,8 +218,6 @@ function stringToNullTermBuffer(s, options = { encoding : 'utf8', maxBufLen : -1
|
||||||
}
|
}
|
||||||
|
|
||||||
const PIPE_REGEXP = /(\|[A-Z\d]{2})/g;
|
const PIPE_REGEXP = /(\|[A-Z\d]{2})/g;
|
||||||
//const ANSI_REGEXP = /[\u001b\u009b][[()#;?]*([0-9]{1,4}(?:;[0-9]{0,4})*)?([0-9A-ORZcf-npqrsuy=><])/g;
|
|
||||||
//const ANSI_OR_PIPE_REGEXP = new RegExp(PIPE_REGEXP.source + '|' + ANSI_REGEXP.source, 'g');
|
|
||||||
const ANSI_OR_PIPE_REGEXP = new RegExp(PIPE_REGEXP.source + '|' + ANSI.getFullMatchRegExp().source, 'g');
|
const ANSI_OR_PIPE_REGEXP = new RegExp(PIPE_REGEXP.source + '|' + ANSI.getFullMatchRegExp().source, 'g');
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -275,12 +273,23 @@ function renderSubstr(str, start, length) {
|
||||||
//
|
//
|
||||||
// See also https://github.com/chalk/ansi-regex/blob/master/index.js
|
// See also https://github.com/chalk/ansi-regex/blob/master/index.js
|
||||||
//
|
//
|
||||||
function renderStringLength(s) {
|
function renderStringLength(s, options = { pipe : true, ansi : true } ) {
|
||||||
let m;
|
let m;
|
||||||
let pos;
|
let pos;
|
||||||
let len = 0;
|
let len = 0;
|
||||||
|
|
||||||
const re = ANSI_OR_PIPE_REGEXP;
|
let re;
|
||||||
|
if(options.pipe && options.ansi) {
|
||||||
|
re = ANSI_OR_PIPE_REGEXP;
|
||||||
|
} else if(options.pipe) {
|
||||||
|
re = PIPE_REGEXP;
|
||||||
|
} else if(options.ansi) {
|
||||||
|
re = ANSI.getFullMatchRegExp();
|
||||||
|
} else {
|
||||||
|
// no options - just return string length.
|
||||||
|
return s.length;
|
||||||
|
}
|
||||||
|
|
||||||
re.lastIndex = 0; // we recycle the rege; reset
|
re.lastIndex = 0; // we recycle the rege; reset
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -49,7 +49,7 @@ function wordWrapText(text, options) {
|
||||||
|
|
||||||
function appendWord() {
|
function appendWord() {
|
||||||
word.match(REGEXP_GOBBLE).forEach( w => {
|
word.match(REGEXP_GOBBLE).forEach( w => {
|
||||||
renderLen = renderStringLength(w);
|
renderLen = renderStringLength(w, { ansi : true, pipe : false } );
|
||||||
|
|
||||||
if(result.renderLen[i] + renderLen > options.width) {
|
if(result.renderLen[i] + renderLen > options.width) {
|
||||||
if(0 === i) {
|
if(0 === i) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue