Skip to content

Commit 4bb27d7

Browse files
committed
added CSI (\x9b) as additionally allowable escape
Added `\x9b` as an additionally allowable ANSI escape code. It's pretty phased out, but can still be used. The difference between the two is that `\x1b` requires a following `[`. Together, both of those characters combined form the CSI. There is the single character alternative, `\x9b`, that doesn't require the `[`. It is less common, I speculate, because faulty ANSI implementations will output `[37;1m` which is more distinct than just `37;1m` - don't quote me on that though. All I know is that it has to do with [C0 and C1 control codes](https://en.wikipedia.org/wiki/C0_and_C1_control_codes) and a bunch of unicode voodoo. I doubt many terminal emulators even support it nowadays but it *is* something you should probably be checking for.
1 parent 5c77031 commit 4bb27d7

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/readline.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -973,8 +973,9 @@ exports.emitKeypressEvents = emitKeypressEvents;
973973
*/
974974

975975
// Regexes used for ansi escape code splitting
976-
const metaKeyCodeReAnywhere = /(?:\x1b)([a-zA-Z0-9])/;
977-
const functionKeyCodeReAnywhere = new RegExp('(?:\x1b+)(O|N|\\[|\\[\\[)(?:' + [
976+
const metaKeyCodeReAnywhere = /(?:(?:\x1b|\x9b))([a-zA-Z0-9])/;
977+
const functionKeyCodeReAnywhere = new RegExp('(?:(?:\x1b|\x9b)+)' +
978+
'(O|N|\\[|\\[\\[)(?:' + [
978979
'(\\d+)(?:;(\\d+))?([~^$])',
979980
'(?:M([@ #!a`])(.)(.))', // mouse
980981
'(?:1;)?(\\d+)?([a-zA-Z])'
@@ -994,11 +995,11 @@ function* emitKeys(stream) {
994995
shift: false
995996
};
996997

997-
if (ch === '\x1b') {
998+
if (ch === '\x1b' || ch === '\x9b') {
998999
escaped = true;
9991000
s += (ch = yield);
10001001

1001-
if (ch === '\x1b') {
1002+
if (ch === '\x1b' || ch === '\x9b') {
10021003
s += (ch = yield);
10031004
}
10041005
}
@@ -1219,7 +1220,7 @@ function* emitKeys(stream) {
12191220
key.name = 'backspace';
12201221
key.meta = escaped;
12211222

1222-
} else if (ch === '\x1b') {
1223+
} else if (ch === '\x1b' || ch === '\x9b') {
12231224
// escape key
12241225
key.name = 'escape';
12251226
key.meta = escaped;

0 commit comments

Comments
 (0)