Last active
August 29, 2015 13:58
-
-
Save maestrow/10173283 to your computer and use it in GitHub Desktop.
nodejs: Processing Ctrl+Z in stdin on Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compare = (buf1, buf2) -> | |
return false if buf1.length != buf2.length | |
for i in [0...buf1.length] | |
return false if buf1[i] != buf2[i] | |
true | |
isCtrlZ = (chunk) -> compare chunk, [26,13,10] | |
input = (cb) -> | |
result = '' | |
stream = process.stdin | |
stream.on 'end', -> cb result | |
stream.on 'data', (chunk) -> | |
if isCtrlZ chunk | |
stream.end() | |
cb result | |
result += chunk | |
stream.resume() | |
input (res) -> console.log res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment