Skip to content

Commit 87bd110

Browse files
committed
Skip superfluous semicolons in escape codes
1 parent 6d9f952 commit 87bd110

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/lib/promptParser.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,17 @@ function readEscapeCodes(
7373
const escapeCodes: (typeof ANSI)[keyof typeof ANSI][] = [];
7474
let localCursor = cursor;
7575
while (!ps1.startsWith('m', localCursor)) {
76-
const escapeCode = parseInt(ps1.substring(localCursor), 10);
77-
if (Number.isNaN(escapeCode) || escapeCode < 0) {
78-
throw new PromptParserError('Invalid escape code', ps1, localCursor);
79-
}
80-
81-
escapeCodes.push(escapeCode);
82-
localCursor += escapeCode.toString().length;
83-
8476
// we consume the separator ';' if it is present
85-
// otherwise the loop will terminate ('m\]') or throw an error in the next iteration
8677
if (ps1.startsWith(';', localCursor)) {
8778
localCursor += 1;
79+
} else {
80+
const escapeCode = parseInt(ps1.substring(localCursor), 10);
81+
if (Number.isNaN(escapeCode) || escapeCode < 0) {
82+
throw new PromptParserError('Invalid escape code', ps1, localCursor);
83+
}
84+
85+
escapeCodes.push(escapeCode);
86+
localCursor += escapeCode.toString().length;
8887
}
8988

9089
if (localCursor >= ps1.length) {

0 commit comments

Comments
 (0)