Skip to content

Commit 96200bb

Browse files
LitoMoresindresorhus
authored andcommittedMar 8, 2019
Support more escape types like links (#29)
Fixes #21 Fixes #28
1 parent e076cd1 commit 96200bb

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed
 

‎index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = options => {
66
}, options);
77

88
const pattern = [
9-
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)',
9+
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
1010
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'
1111
].join('|');
1212

‎readme.md

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ ansiRegex().test('cake');
4040

4141
'\u001B[4mcake\u001B[0m'.match(ansiRegex({onlyFirst: true}));
4242
//=> ['\u001B[4m']
43+
44+
'\u001B]8;;https://github.com\u0007click\u001B]8;;\u0007'.match(ansiRegex());
45+
//=> ['\u001B]8;;https://github.com\u0007', '\u001B]8;;\u0007']
4346
```
4447

4548

‎test.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,20 @@ test('match only first', t => {
4141
t.is('foo\u001B[4mcake\u001B[0m'.match(ansiRegex({onlyFirst: true})).length, 1);
4242
});
4343

44-
test.failing('match "change icon name and window title" in string', t => {
44+
test('match terminal link', t => {
45+
t.regex('\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le\u0007click\u001B]8;;\u0007', ansiRegex());
46+
t.regex('\u001B]8;;mailto:no-replay@mail.com\u0007mail\u001B]8;;\u0007', ansiRegex());
47+
t.deepEqual('\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le\u0007click\u001B]8;;\u0007'.match(ansiRegex()), [
48+
'\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le\u0007',
49+
'\u001B]8;;\u0007'
50+
]);
51+
t.deepEqual('\u001B]8;;mailto:no-reply@mail.com\u0007mail-me\u001B]8;;\u0007'.match(ansiRegex()), [
52+
'\u001B]8;;mailto:no-reply@mail.com\u0007',
53+
'\u001B]8;;\u0007'
54+
]);
55+
});
56+
57+
test('match "change icon name and window title" in string', t => {
4558
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');
4659
});
4760

0 commit comments

Comments
 (0)
Please sign in to comment.