node.jstelnetread-eval-print-loopcontrol-characters

Node JS REPL, Sockets, and Telnet - Tab Completion, Arrow Keys, etc


I have been playing around with Node's REPL. I thought it would be pretty cool to make it available via a Socket, connect to it via Telnet/puTTY/whatever, and debug my server on-the-fly.

I used the example found here: http://nodejs.org/docs/latest/api/repl.html, which basically looks like this...

net.createServer(function (socket) {
  var cmd = repl.start(">", socket);
  //... some other stuff here.... not important
}).listen(5001);

OK, great! Now I can connect to port 5001 with Telnet and interact with the REPL. But, I am running into issues with control characters (i.e. Tab, Ctrl+C, up arrow, down arrow, etc.). How can I get these to work? For example, if I connect using telnet, type "1+1<Enter>", I get 2. But, then when I hit "<Up Arrow><Enter>", I get "...", as if the REPL is waiting for me to finish the command. But, really, all I want to do is see the last command that I executed. I know Telnet likes to hold onto its output until a line feed is inputted, but is there any way to avoid this, as well?

$ telnet localhost 6634
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
>1+1
2
>^[[A
...

EDIT: I also found this issue, which may or may not be related - Arrow keys turn into control characters in Telnet

EDIT 2: Hmmm... rlwrap seems to solve most of my problem:

$ rlwrap telnet localhost 6634

Only thing that doesn't work is tab completions of local/global variables, which I suppose I can live without. I was mostly concerned with the command history. rlwrap is neat!


Solution

  • See above.

    rlwrap telnet localhost 6634