Created
March 22, 2012 03:49
-
-
Save luv2code/2155602 to your computer and use it in GitHub Desktop.
iced-coffee-script console prompt
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
#! /home/matt/local/bin/iced | |
ask = (question, format, callback) -> | |
stdin = process.stdin | |
stdout = process.stdout | |
stdin.resume() | |
stdout.write(question + ": ") | |
stdin.once 'data', (data) -> | |
data = data.toString().trim() | |
if format.test(data) | |
callback(data) | |
else | |
stdout.write("It should match: #{format} \n") | |
ask(question, format, callback) | |
await ask "Name", /.+/, defer name | |
await ask "Email", /^.+@.+$/, defer email | |
console.log "You entered #{name} for name" | |
console.log "You entered #{email} for email" | |
process.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment