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
On Linux, when Node.js (at least, v15.2.0) does a readFileSync of
/dev/tty, it hangs.
The addition of /dev/tty comes from 9bcf45b,
which converts to ESM.
It also switches from reading /dev/stdin, to:
1. on Windows, reading file descriptor 0;
2. on other platforms, reading /dev/tty
(which presumably works on macOS, but not Linux).
However, based on the [Node.js documentation][fd0],
reading file descriptor 0 always reads stdin on all platforms,
thanks to a compatibility layer in Node.js.
Subtly, for Linux specifically, using /dev/stdin
instead of the zero file descriptor, enables the following use-case:
just enter `commonmark` on the console, causing it to wait for prompt.
You can then type text followed by Control-D
to have that text be the input.
| File | Linux | macOS | Windows |
|============|=================|=================|===========|
| | Pipe | ✓ | ✓ | ✓ |
| 0 |--------|-----------------|-----------------|-----------|
| | Prompt | EAGAIN | EAGAIN | TypeError |
|~~~~~~~~~~~~|~~~~~~~~~~~~~~~~~|~~~~~~~~~~~~~~~~~|~~~~~~~~~~~|
| | ✓ | ✓ | ENOENT |
| /dev/stdin |-----------------|-----------------|-----------|
| | ✓ | EAGAIN | ENOENT |
|~~~~~~~~~~~~|~~~~~~~~~~~~~~~~~|~~~~~~~~~~~~~~~~~|~~~~~~~~~~~|
| | (input ignored) | (input ignored) | ENOENT |
| /dev/tty |-----------------|-----------------|-----------|
| | ✓ | ✓ | ENOENT |
Thus we split the decision in a platform-independent way:
1. When in a TTY situation, use /dev/tty.
Except on Windows, which does not have a PTY,
so we manually read lines until we hit ^Z (which is EOF on Windows).
2. Otherwise, use file descriptor 0, which works across all platforms.
[fd0]: https://nodejs.org/api/process.html#process_process_stdin_fd
0 commit comments