Created
July 18, 2013 21:28
-
-
Save gergob/6033253 to your computer and use it in GitHub Desktop.
Contains the implementation of linux's yes command.
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
#!/usr/bin/env node | |
/* | |
This small node.js app should do exactly what the yes linux command does. | |
Quote from man yes: | |
Repeatedly output a line with all specified STRING(s), or `y'. | |
*/ | |
var DEFAULT_TEXT = "y\n"; | |
var CUSTOM_TEXT = ""; | |
var printUsage = function() { | |
process.stdout.write("this will contain the details how to use the program\n"); | |
}; | |
var writeDefaultText = function() { | |
process.stdout.write(DEFAULT_TEXT); | |
}; | |
var writerCustomText = function() { | |
process.stdout.write(CUSTOM_TEXT); | |
}; | |
//handler for CTRL + C | |
process.on("SIGINT", function() { | |
clearInterval(writeDefaultText); | |
clearInterval(writerCustomText); | |
process.exit(0); | |
}); | |
if(process.argv.length == 2) { | |
setInterval(writeDefaultText, 2); | |
} | |
else if(process.argv.length == 3) { | |
CUSTOM_TEXT = process.argv[2]; | |
if(CUSTOM_TEXT[CUSTOM_TEXT.length - 1] != "\n") { | |
CUSTOM_TEXT += "\n"; | |
} | |
setInterval(writerCustomText, 2); | |
} | |
else { | |
printUsage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment