setRawMode fails when running with non-TTY stdin
See original GitHub issueBefore the rest of the issue, I must say that Ink is amazing 👍
An issue I’ve encounted is that when Ink is running in a process where process.stdin.setRawMode
is undefined (for instance in some CI environments), these lines will throw:
https://github.com/vadimdemedes/ink/blob/master/src/components/App.js#L73
https://github.com/vadimdemedes/ink/blob/master/src/components/App.js#L83
This behaviour is detailed by the Node docs on https://nodejs.org/api/tty.html#tty_readstream_setrawmode_mode
When Node.js detects that it is being run with a text terminal (“TTY”) attached, process.stdin will, by default, be initialized as an instance of tty.ReadStream and both process.stdout and process.stderr will, by default be instances of tty.WriteStream. The preferred method of determining whether Node.js is being run within a TTY context is to check that the value of the process.stdout.isTTY property is true
After a search for setRawMode
, it seems that this issue has resurfaced: https://github.com/vadimdemedes/ink/issues/40
While the easy fix would be to wrap all those calls with a check for stdin.isTTY
, that might lead to unexpected behaviour when an app actually expects raw mode to have been set!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:8 (8 by maintainers)
@vadimdemedes What if
<StdinContext>
exposed an additionalisRawModeSupported
bool? It might lead to more 3rd party components adopting a nicer fallback if it was clear in the docs, even if it is currently as simple as checking ifstdin.isTTY
is true or not. Another option would be to simply add info on how to check for that in the docs of StdinContext 👍Nice, thanks @eweilow! Let’s continue discussion there.