diff --git a/core/string_util.js b/core/string_util.js index 20ff3511..4539ea38 100644 --- a/core/string_util.js +++ b/core/string_util.js @@ -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 // diff --git a/core/word_wrap.js b/core/word_wrap.js index d3e78b79..ecb728a5 100644 --- a/core/word_wrap.js +++ b/core/word_wrap.js @@ -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) {