Skip to content

Instantly share code, notes, and snippets.

@luv2code
Created March 22, 2012 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luv2code/2155602 to your computer and use it in GitHub Desktop.
Save luv2code/2155602 to your computer and use it in GitHub Desktop.
iced-coffee-script console prompt
#! /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