Skip to content

Commit

Permalink
Support urxvt escapes (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Qix- authored and sindresorhus committed Jun 20, 2017
1 parent 3dff5e7 commit 69bebf6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
17 changes: 17 additions & 0 deletions fixtures/ansi-codes.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,20 @@ exports.otherCode = new Map([
['3n', ['Response: terminal is not OK', 'DSR']],
['6n', ['Get cursor position', 'DSR']]
]);

// urxvt escapes
exports.urxvt = new Map([
['[5~', ['URxvt.keysym.Prior']],
['[6~', ['URxvt.keysym.Next']],
['[7~', ['URxvt.keysym.Home']],
['[8~', ['URxvt.keysym.End']],
['[A', ['URxvt.keysym.Up']],
['[B', ['URxvt.keysym.Down']],
['[C', ['URxvt.keysym.Right']],
['[D', ['URxvt.keysym.Left']],
['[3;5;5t', ['URxvt.keysym.C-M-q']],
['[3;5;606t', ['URxvt.keysym.C-M-y']],
['[3;1605;5t', ['URxvt.keysym.C-M-e']],
['[3;1605;606t', ['URxvt.keysym.C-M-c']],
[']710;9x15bold\x07', ['URxvt.keysym.font']]
]);
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
'use strict';
module.exports = () => (/[\u001B\u009B][[()#;?]*(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PRZcf-nqry=><]/g);

module.exports = () => {
const pattern = [
'[\\u001b\\u009b][[\\]()#;?]*(?:(?:(?:[a-zA-Z0-9]*(?:;[a-zA-Z0-9]*)*)?\\x07)',
'(?:(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-PRZcf-ntqry=><~]))'
].join('|');

return new RegExp(pattern, 'g');
};

0 comments on commit 69bebf6

Please sign in to comment.