node/deps/npm/node_modules/ansi/examples/starwars.js

47 lines
982 B
JavaScript
Raw Normal View History

2012-07-14 02:40:38 +08:00
#!/usr/bin/env node
/**
* A little script to play the ASCII Star Wars, but with a hidden cursor,
* since over `telnet(1)` the cursor remains visible which is annoying.
*/
process.title = 'starwars'
var net = require('net')
, cursor = require('../')(process.stdout)
2013-10-25 00:21:59 +08:00
, color = process.argv[2]
2012-07-14 02:40:38 +08:00
// enable "raw mode" so that keystrokes aren't visible
process.stdin.resume()
if (process.stdin.setRawMode) {
process.stdin.setRawMode(true)
} else {
require('tty').setRawMode(true)
}
// connect to the ASCII Star Wars server
var socket = net.connect(23, 'towel.blinkenlights.nl')
socket.on('connect', function () {
2013-10-25 00:21:59 +08:00
if (color in cursor.fg) {
cursor.fg[color]()
}
2012-07-14 02:40:38 +08:00
cursor.hide()
socket.pipe(process.stdout)
})
process.stdin.on('data', function (data) {
if (data.toString() === '\u0003') {
// Ctrl+C; a.k.a SIGINT
socket.destroy()
process.stdin.pause()
}
})
process.on('exit', function () {
2013-10-25 00:21:59 +08:00
cursor
.show()
.fg.reset()
.write('\n')
2012-07-14 02:40:38 +08:00
})