Skip to content

Instantly share code, notes, and snippets.

@vladkotu
Forked from anonymous/exit node
Last active December 10, 2015 00:29
Show Gist options
  • Save vladkotu/4351913 to your computer and use it in GitHub Desktop.
Save vladkotu/4351913 to your computer and use it in GitHub Desktop.
// Unpause stream for stdin
process.stdin.resume();
process.stdin.setEncoding('utf8');
// Set raw mode (read by char)
// http://unix.stackexchange.com/questions/21752/whats-the-difference-between-a-raw-and-a-cooked-device-driver
process.stdin.setRawMode(true);
// Subscribe to data retrieving event
process.stdin.on('data', function (chunk) {
// Check if end of data stream reached (http://en.wikipedia.org/wiki/List_of_Unicode_characters)
if (chunk === '\u0003'){
console.log("Bye bye, User!");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment