Tags
nodejs
Created
May 7, 2018 1:05 PM
shell 中启动的进程是 shell fork 的,并且继承了 shell 的 stdin stdout stderr
而一切皆文件, stdin 是可以用 fs 来同步读取的
实现上, realine 在读取 TTY 的数据时, 是通过 input.on('keypress', onkeypress) 时发现用户按下了回车键来判断是新的 line (块?)的, 而读取一般的 stream 时, 则是通过缓存数据然后用正则 .test 来判断是否为 new line 的.
http://stackoverflow.com/questions/3430939/node-js-readsync-from-stdin