Fix EOF detection

Fixes issue with Ctrl-D having to be pressed twice when reading from
terminal.