From 96200bb3dd0aa955d1546b4edf5e0a8d211e1152 Mon Sep 17 00:00:00 2001 From: LitoMore Date: Fri, 8 Mar 2019 14:07:08 +0800 Subject: [PATCH] Support more escape types like links (#29) Fixes #21 Fixes #28 --- index.js | 2 +- readme.md | 3 +++ test.js | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 76d354a..c254480 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ module.exports = options => { }, options); const pattern = [ - '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)', + '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)', '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))' ].join('|'); diff --git a/readme.md b/readme.md index 7212145..d19c446 100644 --- a/readme.md +++ b/readme.md @@ -40,6 +40,9 @@ ansiRegex().test('cake'); '\u001B[4mcake\u001B[0m'.match(ansiRegex({onlyFirst: true})); //=> ['\u001B[4m'] + +'\u001B]8;;https://github.com\u0007click\u001B]8;;\u0007'.match(ansiRegex()); +//=> ['\u001B]8;;https://github.com\u0007', '\u001B]8;;\u0007'] ``` diff --git a/test.js b/test.js index acc59de..f8b4519 100644 --- a/test.js +++ b/test.js @@ -41,7 +41,20 @@ test('match only first', t => { t.is('foo\u001B[4mcake\u001B[0m'.match(ansiRegex({onlyFirst: true})).length, 1); }); -test.failing('match "change icon name and window title" in string', t => { +test('match terminal link', t => { + t.regex('\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le\u0007click\u001B]8;;\u0007', ansiRegex()); + t.regex('\u001B]8;;mailto:no-replay@mail.com\u0007mail\u001B]8;;\u0007', ansiRegex()); + t.deepEqual('\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le\u0007click\u001B]8;;\u0007'.match(ansiRegex()), [ + '\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le\u0007', + '\u001B]8;;\u0007' + ]); + t.deepEqual('\u001B]8;;mailto:no-reply@mail.com\u0007mail-me\u001B]8;;\u0007'.match(ansiRegex()), [ + '\u001B]8;;mailto:no-reply@mail.com\u0007', + '\u001B]8;;\u0007' + ]); +}); + +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'); });