Skip to content

Instantly share code, notes, and snippets.

@changtimwu
Created May 24, 2012 01:02
Show Gist options
  • Save changtimwu/2778715 to your computer and use it in GitHub Desktop.
Save changtimwu/2778715 to your computer and use it in GitHub Desktop.
demostrate how to delay prompt after job completion
readline = require('readline')
rl = readline.createInterface(process.stdin, process.stdout)
prefix = 'OHAI> '
rl.on 'line', (line)->
switch line.trim()
when 'hello'
setTimeout (->
console.log 'world!'
rl.prompt()
), 1000
break
else
console.log 'Say what? I might have heard `' + line.trim() + '`'
break
rl.setPrompt prefix, prefix.length
rl.on 'close', ->
console.log 'Have a great day!'
process.exit 0
console.log prefix + 'Good to see you. Try typing stuff.'
rl.setPrompt prefix, prefix.length
rl.prompt()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment