Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readline: fix key name for function keys combined with modifiers #35268

Merged
merged 1 commit into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/internal/readline/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,13 @@ function* emitKeys(stream) {

// Parse the key itself
switch (code) {
/* xterm/gnome ESC O letter */
/* xterm/gnome ESC [ letter (with modifier) */
case '[P': key.name = 'f1'; break;
case '[Q': key.name = 'f2'; break;
case '[R': key.name = 'f3'; break;
case '[S': key.name = 'f4'; break;

/* xterm/gnome ESC O letter (without modifier) */
case 'OP': key.name = 'f1'; break;
case 'OQ': key.name = 'f2'; break;
case 'OR': key.name = 'f3'; break;
Expand Down Expand Up @@ -296,12 +302,15 @@ function* emitKeys(stream) {
} else if (ch === '\r') {
// carriage return
key.name = 'return';
key.meta = escaped;
} else if (ch === '\n') {
// Enter, should have been called linefeed
key.name = 'enter';
key.meta = escaped;
} else if (ch === '\t') {
// tab
key.name = 'tab';
key.meta = escaped;
} else if (ch === '\b' || ch === '\x7f') {
// backspace or ctrl+h
key.name = 'backspace';
Expand Down
24 changes: 23 additions & 1 deletion test/parallel/test-readline-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,13 @@ addTest('io.JS', [
]);

// Named characters
addTest('\n\r\t', [
addTest('\n\r\t\x1b\n\x1b\r\x1b\t', [
{ name: 'enter', sequence: '\n' },
{ name: 'return', sequence: '\r' },
{ name: 'tab', sequence: '\t' },
{ name: 'enter', sequence: '\x1b\n', meta: true },
{ name: 'return', sequence: '\x1b\r', meta: true },
{ name: 'tab', sequence: '\x1b\t', meta: true },
]);

// Space and backspace
Expand Down Expand Up @@ -132,6 +135,25 @@ addTest('a\x1baA\x1bA', [
{ name: 'a', sequence: '\x1bA', meta: true, shift: true },
]);

// xterm/gnome ESC [ letter (with modifiers)
/* eslint-disable max-len */
addTest('\x1b[2P\x1b[3P\x1b[4P\x1b[5P\x1b[6P\x1b[7P\x1b[8P\x1b[3Q\x1b[8Q\x1b[3R\x1b[8R\x1b[3S\x1b[8S', [
{ name: 'f1', sequence: '\x1b[2P', code: '[P', shift: true, meta: false, ctrl: false },
{ name: 'f1', sequence: '\x1b[3P', code: '[P', shift: false, meta: true, ctrl: false },
{ name: 'f1', sequence: '\x1b[4P', code: '[P', shift: true, meta: true, ctrl: false },
{ name: 'f1', sequence: '\x1b[5P', code: '[P', shift: false, meta: false, ctrl: true },
{ name: 'f1', sequence: '\x1b[6P', code: '[P', shift: true, meta: false, ctrl: true },
{ name: 'f1', sequence: '\x1b[7P', code: '[P', shift: false, meta: true, ctrl: true },
{ name: 'f1', sequence: '\x1b[8P', code: '[P', shift: true, meta: true, ctrl: true },
{ name: 'f2', sequence: '\x1b[3Q', code: '[Q', meta: true },
{ name: 'f2', sequence: '\x1b[8Q', code: '[Q', shift: true, meta: true, ctrl: true },
{ name: 'f3', sequence: '\x1b[3R', code: '[R', meta: true },
{ name: 'f3', sequence: '\x1b[8R', code: '[R', shift: true, meta: true, ctrl: true },
{ name: 'f4', sequence: '\x1b[3S', code: '[S', meta: true },
{ name: 'f4', sequence: '\x1b[8S', code: '[S', shift: true, meta: true, ctrl: true },
]);
/* eslint-enable max-len */

// xterm/gnome ESC O letter
addTest('\x1bOP\x1bOQ\x1bOR\x1bOS', [
{ name: 'f1', sequence: '\x1bOP', code: 'OP' },
Expand Down