Revert "Fix word wrap crash reported by user when pipe codes are in play"
This reverts commit 0a486d290f
.
This commit is contained in:
parent
1261af00c3
commit
aecc24079f
|
@ -218,6 +218,8 @@ function stringToNullTermBuffer(s, options = { encoding : 'utf8', maxBufLen : -1
|
|||
}
|
||||
|
||||
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');
|
||||
|
||||
//
|
||||
|
@ -273,23 +275,12 @@ function renderSubstr(str, start, length) {
|
|||
//
|
||||
// See also https://github.com/chalk/ansi-regex/blob/master/index.js
|
||||
//
|
||||
function renderStringLength(s, options = { pipe : true, ansi : true } ) {
|
||||
function renderStringLength(s) {
|
||||
let m;
|
||||
let pos;
|
||||
let len = 0;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
const re = ANSI_OR_PIPE_REGEXP;
|
||||
re.lastIndex = 0; // we recycle the rege; reset
|
||||
|
||||
//
|
||||
|
|
|
@ -49,7 +49,7 @@ function wordWrapText(text, options) {
|
|||
|
||||
function appendWord() {
|
||||
word.match(REGEXP_GOBBLE).forEach( w => {
|
||||
renderLen = renderStringLength(w, { ansi : true, pipe : false } );
|
||||
renderLen = renderStringLength(w);
|
||||
|
||||
if(result.renderLen[i] + renderLen > options.width) {
|
||||
if(0 === i) {
|
||||
|
|
Loading…
Reference in New Issue