From 1a1d672c38da7a2bd49a37ab15c3667b6bafa644 Mon Sep 17 00:00:00 2001 From: Im-Beast Date: Mon, 11 Sep 2023 16:28:35 +0200 Subject: [PATCH] fix: re-apply style on each column in `getMultiCodePointCharacters` --- src/utils/strings.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/utils/strings.ts b/src/utils/strings.ts index 15c5c0c..f7f1c7c 100644 --- a/src/utils/strings.ts +++ b/src/utils/strings.ts @@ -17,15 +17,27 @@ export function getMultiCodePointCharacters(text: string): string[] { if (matched?.includes("\x1b")) { const arr: string[] = []; let i = 0; - let ansi = false; + let ansi = 0; + let lastStyle = ""; for (const char of matched) { arr[i] ??= ""; - arr[i] += char; + arr[i] += lastStyle + char; if (char === "\x1b") { - ansi = true; + ++ansi; + lastStyle += "\x1b"; } else if (ansi) { - if (char === "m") ansi = false; + lastStyle += char; + + if (ansi === 3 && char === "m" && lastStyle[lastStyle.length - 2] === "0") { + lastStyle = ""; + } + + if (char === "m") { + ansi = 0; + } else { + ++ansi; + } } else { ++i; }