Skip to content

Instantly share code, notes, and snippets.

@TooTallNate
Created April 17, 2012 21:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TooTallNate/a7017a1dddc543238012 to your computer and use it in GitHub Desktop.
Save TooTallNate/a7017a1dddc543238012 to your computer and use it in GitHub Desktop.
Usage of node-telnet with node's REPL, in full-featured "terminal" mode
/**
* Usage of node-telnet with node's REPL, in full-featured "terminal" mode.
* (Requires node >= v0.7.7)
*/
var telnet = require('telnet')
, repl = require('repl')
telnet.createServer(function (client) {
client.on('window size', function (e) {
if (e.command === 'sb') {
// a real "resize" event; 'readline' listens for this
client.columns = e.width
client.rows = e.height
client.emit('resize')
}
})
// 'readline' will call `setRawMode` when it is a function
client.setRawMode = setRawMode
// make unicode characters work properly
client.do.transmit_binary()
// emit 'window size' events
client.do.window_size()
// create the REPL
var r = repl.start({
input: client
, output: client
, prompt: 'telnet repl> '
, terminal: true
, useGlobal: false
}).on('exit', function () {
client.end()
})
r.context.r = r
r.context.client = client
r.context.socket = client
}).listen(1337)
function setRawMode (mode) {
if (mode) {
this.do.suppress_go_ahead()
this.will.suppress_go_ahead()
this.will.echo()
} else {
this.dont.suppress_go_ahead()
this.wont.suppress_go_ahead()
this.wont.echo()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment