From dda4ad66980affe1166b901cbc386062d5eecfb7 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Thu, 24 Aug 2017 22:20:44 -0600 Subject: [PATCH] Fix some prepAnsi code, add insert() method --- core/string_util.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/string_util.js b/core/string_util.js index 6db92b25..b7cdb081 100644 --- a/core/string_util.js +++ b/core/string_util.js @@ -12,6 +12,7 @@ const _ = require('lodash'); exports.stylizeString = stylizeString; exports.pad = pad; +exports.insert = insert; exports.replaceAt = replaceAt; exports.isPrintable = isPrintable; exports.stripAllLineFeeds = stripAllLineFeeds; @@ -172,6 +173,10 @@ function pad(s, len, padChar, dir, stringSGR, padSGR, useRenderLen) { return stringSGR + s; } +function insert(s, index, substr) { + return `${s.slice(0, index)}${substr}${s.slice(index)}`; +} + function replaceAt(s, n, t) { return s.substring(0, n) + t + s.substring(n + 1); } @@ -484,6 +489,10 @@ function prepAnsi(input, options, cb) { case 'new' : line = _.trimStart(line); if(line) { + if(output) { + output += '\r\n'; + } + textState = 'cont'; } break; @@ -543,6 +552,7 @@ function isAnsi(input) { }); */ + // :TODO: if a similar method is kept, use exec() until threshold const ANSI_DET_REGEXP = /(?:\x1b\x5b)[\?=;0-9]*?[ABCDEFGHJKLMSTfhlmnprsu]/g; const m = input.match(ANSI_DET_REGEXP) || []; return m.length >= 4; // :TODO: do this reasonably, e.g. a percent or soemthing