Created
May 24, 2012 01:02
-
-
Save changtimwu/2778715 to your computer and use it in GitHub Desktop.
demostrate how to delay prompt after job completion
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
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