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: Function keys (e.g. F1) return "undefined" key name #35251

Closed
elie-g opened this issue Sep 18, 2020 · 0 comments · Fixed by #35268
Closed

Readline: Function keys (e.g. F1) return "undefined" key name #35251

elie-g opened this issue Sep 18, 2020 · 0 comments · Fixed by #35268

Comments

@elie-g
Copy link
Contributor

elie-g commented Sep 18, 2020

What steps will reproduce the bug?

  1. Execute the code below in a terminal.
  2. Press Alt+F3 (see Additionnal information).
const { StringDecoder } = require('string_decoder')
const { emitKeypressEvents } = require('readline')

const stdin = process.openStdin();
emitKeypressEvents(stdin);
if (stdin.isTTY) {
  console.log('Standard input is a TTY');
  stdin.setRawMode(true);
}

const strDecoder = new StringDecoder('utf8');

const escapeEsc = (str) => str?.replace(/\x1b/g, 'ESC');

stdin.on('keypress', (str, key) => {
  // key.name === "undefined" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< HERE
  console.log('KEYPRESS => data: «%o», key: %o', escapeEsc(str), key);
});

stdin.on('data', (data) => {
  const str = strDecoder.write(data);
  console.log('DATA => decoded: «%s», raw: %o', escapeEsc(str), data);
});

How often does it reproduce? Is there a required condition?

Every time!

What is the expected behavior?

key.name should contain the name of the function key (e.g. "f1").
See Additional information.

What do you see instead?

key.name contains "undefined" (as a string / not undefined).
See Additional information.

Output after pressing Alt + F3
webstorm-output

Additional information

Tested key combinations (expected/current result)
Key combo Expected
key.name
Current
key.name
Matches
expectation?
Alt + F1 "f1" ??? ???
Alt + F2 "f2" ??? ???
Alt + F3 "f3" "undefined" N
Alt + F4 "f4" ??? ???
Alt + F5 "f5" "f5" Y
Alt + F6 "f6" ??? ???
Alt + F7 "f7" "f7" Y
Alt + F8 "f8" ??? ???
Alt + F9 "f9" "f9" Y
Alt + F10 "f10" "f10" Y
Alt + F11 "f11" ??? ???
Alt + F12 "f12" "f12" Y
Alt + Shift + F1 "f1" "undefined" N
Alt + Shift + F2 "f2" ??? ???
Alt + Shift + F3 "f3" "undefined" N
Alt + Shift + F4 "f4" "undefined" N
Alt + Shift + F5 "f5" "f5" Y
Alt + Shift + F6 "f6" ??? ???
Alt + Shift + F7 "f7" "f7" Y
Alt + Shift + F8 "f8" "f8" Y
Alt + Shift + F9 "f9" "f9" Y
Alt + Shift + F10 "f10" ??? ???
Alt + Shift + F11 "f11" ??? ???
Alt + Shift + F12 "f12" "f12" Y
Ctrl + F1 "f1" "undefined" N
Ctrl + F2 "f2" ??? ???
Ctrl + F3 "f3" "undefined" N
Ctrl + F4 "f4" "undefined" N
Ctrl + F5 "f5" "f5" Y
Ctrl + F6 "f6" "f6" Y
Ctrl + F7 "f7" "f7" Y
Ctrl + F8 "f8" "f8" Y
Ctrl + F9 "f9" "f9" Y
Ctrl + F10 "f10" "f10" Y
Ctrl + F11 "11" ??? ???
Ctrl + F12 "f12" "f12" Y
Ctrl + Shift + F1 "f1" "undefined" N
Ctrl + Shift + F2 "f2" ??? ???
Ctrl + Shift + F3 "f3" "undefined" N
Ctrl + Shift + F4 "f4" "undefined" N
Ctrl + Shift + F5 "f5" "f5" Y
Ctrl + Shift + F6 "f6" "f6" Y
Ctrl + Shift + F7 "f7" "f7" Y
Ctrl + Shift + F8 "f8" "f8" Y
Ctrl + Shift + F9 "f9" "f9" Y
Ctrl + Shift + F10 "f10" ??? ???
Ctrl + Shift + F11 "11" ??? ???
Ctrl + Shift + F12 "f12" "f12" Y

The key combinations where the 3rd and 4th columns contain ??? could not be tested cause they were already bound to something else like Alt + F4 which closes the application.

@elie-g elie-g changed the title Readline: ALT + Function keys (e.g. F1) return undefined key name Readline: Function keys (e.g. F1) return undefined key name Sep 18, 2020
@elie-g elie-g changed the title Readline: Function keys (e.g. F1) return undefined key name Readline: Function keys (e.g. F1) return "undefined" key name Sep 18, 2020
@Trott Trott closed this as completed in 17ebd46 Sep 21, 2020
ruyadorno pushed a commit that referenced this issue Sep 21, 2020
Fixes: #35251

PR-URL: #35268
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
joesepi pushed a commit to joesepi/node that referenced this issue Jan 8, 2021
Fixes: nodejs#35251

PR-URL: nodejs#35268
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant