Skip to content

Commit

Permalink
fix: re-apply style on each column in getMultiCodePointCharacters
Browse files Browse the repository at this point in the history
  • Loading branch information
Im-Beast committed Sep 11, 2023
1 parent bf137a8 commit 1a1d672
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/utils/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 1a1d672

Please sign in to comment.