Skip to content

Commit 4004fa4

Browse files
committed
add a comment explaining the regex pattern for ANSI escape sequences
1 parent 354b8f0 commit 4004fa4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

packages/core/src/lib/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ export function breakLines(content: string, width: number): string {
1717
let escapeSequence = '';
1818
let inEscape = false;
1919

20-
for (let i = 0; i < line.length; i++) {
21-
const char = line[i]!;
22-
20+
for (const char of line) {
2321
// Detect start of ANSI escape code
2422
if (char === '\x1b') {
2523
inEscape = true;
@@ -31,6 +29,8 @@ export function breakLines(content: string, width: number): string {
3129
if (inEscape) {
3230
escapeSequence += char;
3331

32+
// ANSI escape sequences always end with a letter (eg., 'm' in '\x1b[31m')
33+
// This marks the end of the sequence so we can append it without counting its width
3434
if (/[a-zA-Z]/.test(char)) {
3535
inEscape = false;
3636
currentLine += escapeSequence;

0 commit comments

Comments
 (0)