Document that readline.emitKeypressEvents only works when tty is in raw mode #6626
Copy link
Copy link
Closed
Labels
docIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.readlineIssues and PRs related to the built-in readline module.Issues and PRs related to the built-in readline module.
Description
- Version: 6.0.0
- Platform: osx 10.11.4,
uname -a: 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64 - Subsystem: readline.emitKeypressEvents
process.stdin does not emit keypress after readline.emitKeypressEvents(process.stdin), but does when a readline interface created.
const readline = require('readline')
// const rl = readline.createInterface({
// input: process.stdin,
// output: process.stdout
// })
readline.emitKeypressEvents(process.stdin)
process.stdin.on('keypress', () => {
process.stdout.write('.')
})What happens: On keypress, event handler is not called. If a readline interface is created, the event handler is called.
Expected: stdin to start emitting keypress-events.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
docIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.readlineIssues and PRs related to the built-in readline module.Issues and PRs related to the built-in readline module.
Activity
addaleax commentedon May 7, 2016
Does setting
process.stdin.setRawMode(true);help you?arve0 commentedon May 7, 2016
@addaleax Yes, it does. The event handler is called, and terminal echo turns off.
addaleax commentedon May 7, 2016
That is expected in raw mode, yes. I am not sure whether there’s another way to make process.stdin unbuffered/return characters as they are typed…
Is your question answered by this?
arve0 commentedon May 7, 2016
Kind of. I guess the documentation should state that raw mode or a readline interface is needed.
A drawback with raw mode though, is that
SIGINTis disabled. Any way around that, without implementing it oneself?This does not seem to work:
Any idea why?
arve0 commentedon May 7, 2016
To be more clear, this is needed in raw mode
but not when using a readline interface.
addaleax commentedon May 7, 2016
Yeah, I guess so… The readline interface sets raw mode itself if the input is a terminal, that’s why that’s working.
If you “just” want as close to the original Ctrl+C behaviour as possible, you may want to use
process.kill(process.pid, 'SIGINT')rather thanprocess.emit('SIGINT'). The latter one does not actually send the signal, just emits the event to any JS listeners for it.arve0 commentedon May 7, 2016
Aha, thanks!
[-]readline.emitKeypressEvents only works when a readline interface is created[/-][+]Document that readline.emitKeypressEvents only works when tty is in raw mode[/+]doc: readline.emitKeypressEvents and raw mode
doc: readline.emitKeypressEvents and raw mode