You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Document that readline.emitKeypressEvents only works when tty is in raw mode #6626
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.
I guess the documentation should state that raw mode or a readline interface is needed.
Yeah, I guess so… The readline interface sets raw mode itself if the input is a terminal, that’s why that’s working.
To be more clear, this is needed in raw mode
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 than process.emit('SIGINT'). The latter one does not actually send the signal, just emits the event to any JS listeners for it.
changed the title [-]readline.emitKeypressEvents only works when a readline interface is created[/-][+]Document that readline.emitKeypressEvents only works when tty is in raw mode[/+]on May 7, 2016
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