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

会有一股神秘感。 提交于 2019-12-10 20:24:31

问题


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!


回答1:


See above.

rlwrap telnet localhost 6634



来源:https://stackoverflow.com/questions/8649861/node-js-repl-sockets-and-telnet-tab-completion-arrow-keys-etc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!