From f6fa684cba4c02dd5b1f9ed3eba91f9e33eacf05 Mon Sep 17 00:00:00 2001 From: Im-Beast Date: Fri, 4 Nov 2022 18:01:12 +0100 Subject: [PATCH] fix: canvas draw() performance/crashing issues under some circumstances --- src/canvas.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/canvas.ts b/src/canvas.ts index 10cf61c..ed9a1b9 100644 --- a/src/canvas.ts +++ b/src/canvas.ts @@ -111,7 +111,8 @@ export class Canvas extends EventEmitter { return; } - const noResetStyle = value.match(/((.|\s)+?)\x1b\[0m/)?.[1] ?? ""; + const resetStyleIndex = value.indexOf("\x1b[0m"); + const noResetStyle = resetStyleIndex === -1 ? "" : value.substring(0, resetStyleIndex); const borderIndex = noResetStyle.lastIndexOf("m", noResetStyle.length - stripped.length); const distinctStyles = (