Last active
December 26, 2015 19:09
-
-
Save alfonsodev/7199536 to your computer and use it in GitHub Desktop.
ncurses snippet for nodejs
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
//first do a 'npm install ncurses' | |
var nc = require('ncurses'), | |
widgets = require('./node_modules/ncurses/lib/widgets'); | |
var win = new nc.Window(); | |
nc.showCursor = false; | |
widgets.MessageBox('Do you want to continue', { buttons: ['OK', 'Cancel'], pos: 'center'}, function(choice) { | |
win.refresh(); | |
if(choice == 'OK') { | |
win.centertext(0, 'Press a key to know the code, [q] or [scape] to quit.'); | |
win.refresh(); | |
} else { | |
win.centertext(0, 'Bye! '); | |
setTimeout(function() { win.close(); }, 1000); | |
} | |
}); | |
win.on('inputChar', function(char, charCode, isKey) { | |
win.refresh(); | |
win.centertext(1, 'charCode: ' + charCode); | |
if(charCode == 27 || charCode == 113) { | |
win.centertext(5, 'Bye!' ); | |
setTimeout(function() { win.close(); }, 500); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment