Skip to content

Instantly share code, notes, and snippets.

@maestrow
Last active August 29, 2015 13:58
Show Gist options
  • Save maestrow/10173283 to your computer and use it in GitHub Desktop.
Save maestrow/10173283 to your computer and use it in GitHub Desktop.
nodejs: Processing Ctrl+Z in stdin on Windows
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