Skip to content

Commit df7d75f

Browse files
authored
Support colon separated parameters to control sequences (#62)
1 parent 827322a commit df7d75f

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export default function ansiRegex({onlyFirst = false} = {}) {
33
const ST = '(?:\\u0007|\\u001B\\u005C|\\u009C)';
44
const pattern = [
55
`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?${ST})`,
6-
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))',
6+
'(?:(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))',
77
].join('|');
88

99
return new RegExp(pattern, onlyFirst ? undefined : 'g');

test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ test('match "change icon name and window title" in string', t => {
6161
t.is('\u001B]0;sg@tota:~/git/\u0007\u001B[01;32m[sg@tota\u001B[01;37m misc-tests\u001B[01;32m]$'.match(ansiRegex())[0], '\u001B]0;sg@tota:~/git/\u0007');
6262
});
6363

64+
test('match colon separated sequence arguments', t => {
65+
t.regex('\u001B[38:2:68:68:68:48:2:0:0:0m', ansiRegex());
66+
t.is('\u001B[38:2:68:68:68:48:2:0:0:0m'.match(ansiRegex())[0], '\u001B[38:2:68:68:68:48:2:0:0:0m');
67+
});
68+
6469
// Testing against extended codes (excluding codes ending in 0-9)
6570
for (const [codeSetKey, codeSetValue] of Object.entries(ansiCodes)) {
6671
for (const [code, codeInfo] of codeSetValue) {

0 commit comments

Comments
 (0)