From 2e31a9c49957c521e7ecd8127c6db56f00451d66 Mon Sep 17 00:00:00 2001 From: Muhammad Saheed Date: Sun, 17 Aug 2025 19:02:21 +0530 Subject: [PATCH] Support colon separated parameters to control sequences --- index.js | 2 +- test.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index ddfdba3..fafabf6 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ export default function ansiRegex({onlyFirst = false} = {}) { const ST = '(?:\\u0007|\\u001B\\u005C|\\u009C)'; const pattern = [ `[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?${ST})`, - '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))', + '(?:(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))', ].join('|'); return new RegExp(pattern, onlyFirst ? undefined : 'g'); diff --git a/test.js b/test.js index 4d092d0..aedd80a 100644 --- a/test.js +++ b/test.js @@ -61,6 +61,11 @@ test('match "change icon name and window title" in string', t => { 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'); }); +test('match colon separated sequence arguments', t => { + t.regex('\u001B[38:2:68:68:68:48:2:0:0:0m', ansiRegex()); + 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'); +}); + // Testing against extended codes (excluding codes ending in 0-9) for (const [codeSetKey, codeSetValue] of Object.entries(ansiCodes)) { for (const [code, codeInfo] of codeSetValue) {