-
-
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
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
/** | |
* 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