heapwolf / prompt-sync

a synchronous prompt for node.js
MIT License
218 stars 42 forks source link

windows and node 0.10 support (closes #4 and #8) #9

Closed davidmarkclements closed 8 years ago

davidmarkclements commented 8 years ago
  1. Windows has no /dev/stdin
  2. process.stdin.fd however already contains the STDIN fd (0) on all platforms
  3. fs.readSync(process.stdin.fd, 'rs') works on Windows, on Node v0.10+
  4. fs.readSync(process.stdin.fd, 'rs') works on non-windows on Node 0.12+ (at least tested on OS X)
  5. reading from /dev/stdin on v0.10 on non-windows fails also (at least on OS X)
  6. reading from /dev/tty WORKS on 0.10 on non-windows

So,

if v0.12+ OR windows we read from process.stdin.fd if < 0.12 AND NOT windows we read from /dev/tty

Note: Edge case - will fail in REPL in windows (EBADF)