3

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!

Community
  • 1
  • 1
BMiner
  • 16,669
  • 12
  • 53
  • 53

2 Answers2

1

See above.

rlwrap telnet localhost 6634

BMiner
  • 16,669
  • 12
  • 53
  • 53
  • you could mimic tab completion using the -c -f switches: http://blog.lishman.com/2008/04/rlwrap.html obviously you'll need a node.js keyword list – booyaa Jun 13 '13 at 08:22
0

To get the built-in tab completion and history in REPLServer working on a socket you need to explicitly provide the terminal: true option when instantiating REPLServer to tell it behave as if it's connected to a terminal, and then on the client side you put the terminal in raw mode (see e.g. repl-client on npm).

Matthijs
  • 704
  • 7
  • 8