Created
November 27, 2013 03:39
-
-
Save Juriy/7670359 to your computer and use it in GitHub Desktop.
This is an example for Node.js Boot Camp training for EPAM Systems. Day 1.
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
// ESC[#A moves cursor up # lines | |
// ESC[#B moves cursor down # lines | |
// ESC[#C moves cursor right # spaces | |
// ESC[#D moves cursor left # spaces | |
// Script can be written as is | |
process.stdout.write("\u001b[2J\u001b[0;0H"); | |
process.stdout.write("\u001b[0;30m"); | |
process.stdout.write("Hello there\n"); | |
process.stdout.write("\u001b[0;31m"); | |
process.stdout.write("Hello there\n"); | |
process.stdout.write("\u001b[0;32m"); | |
process.stdout.write("Hello there\n"); | |
process.stdout.write("\u001b[0;33m"); | |
process.stdout.write("Hello there\n"); | |
process.stdout.write("\u001b[0;34m"); | |
process.stdout.write("Hello there\n"); | |
process.stdout.write("\u001b[0;35m"); | |
process.stdout.write("Hello there\n"); | |
process.stdout.write("\u001b[0;36m"); | |
process.stdout.write("Hello there\n"); | |
process.stdout.write("\u001b[0;37m"); | |
process.stdout.write("Hello there\n"); | |
process.stdout.write("\u001b[1;30m"); | |
process.stdout.write("Hello there\n"); | |
process.stdout.write("\u001b[1;31m"); | |
process.stdout.write("Hello there\n"); | |
process.stdout.write("\u001b[1;32m"); | |
process.stdout.write("Hello there\n"); | |
process.stdout.write("\u001b[1;33m"); | |
process.stdout.write("Hello there\n"); | |
process.stdout.write("\u001b[1;34m"); | |
process.stdout.write("Hello there\n"); | |
process.stdout.write("\u001b[1;35m"); | |
process.stdout.write("Hello there\n"); | |
process.stdout.write("\u001b[1;36m"); | |
process.stdout.write("Hello there\n"); | |
process.stdout.write("\u001b[1;37m"); | |
process.stdout.write("Hello there\n"); | |
process.stdout.write("\u001b[31m"); | |
process.stdout.write("Hello there\n"); | |
process.stdout.write("\u001b[0m"); | |
process.stdout.write("Hello there\n"); | |
process.stdin.setRawMode(true); | |
// resume stdin in the parent process (node app won't quit all by itself | |
// unless an error or process.exit() happens) | |
process.stdin.resume(); | |
// switch from binary to something more useful | |
process.stdin.setEncoding('utf8'); | |
// on any data into stdin | |
process.stdin.on( 'data', function(key) { | |
//moveTo(0, 0); | |
//process.stdout.write("" + key.charCodeAt(0)); | |
//process.stdout.write( key ); | |
if (key === "\u001b[A") { | |
// down arrow | |
process.stdout.write("[up]"); | |
} else if (key === "\u001b[B") { | |
process.stdout.write("[down]"); | |
} else if (key === "\u001b[C") { | |
process.stdout.write("[right]"); | |
} else if (key === "\u001b[D") { | |
process.stdout.write("[left]"); | |
} | |
if (key === "\u001b") { | |
process.exit(); | |
} | |
}); | |
var map = [ | |
" ┌───────┐ ", | |
" ┌───────┐ │·······│ ", | |
" │·······│ │·······│ ", | |
" │·······│ │·······│ ", | |
" │········░░░░░········│ ", | |
" │·······│ │·······│ ", | |
" │·······│ │·······│ ", | |
" └───────┘ └───────┘ " | |
]; | |
setTimeout(function() { | |
// Clear and move to (0, 0) | |
process.stdout.write("\u001b[2J\u001b[0;0H"); | |
for (var i = 0; i < map.length; i++) { | |
console.log(map[i]); | |
} | |
}, 2000); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment