Add NODE_NO_READLINE check for REPL
Setting this environmental variable to a non-zero integer will start all REPL interfaces without readline. For use with rlwrap.
This commit is contained in:
parent
0377b12964
commit
adc06dd705
@ -2760,21 +2760,18 @@ The escape function used by `querystring.stringify`, provided so that it could b
|
|||||||
|
|
||||||
The unescape function used by `querystring.parse`, provided so that it could be overridden if necessary.
|
The unescape function used by `querystring.parse`, provided so that it could be overridden if necessary.
|
||||||
|
|
||||||
|
|
||||||
## REPL
|
## REPL
|
||||||
|
|
||||||
A Read-Eval-Print-Loop is available both as a standalone program and easily
|
A Read-Eval-Print-Loop (REPL) is available both as a standalone program and easily
|
||||||
includable in other programs. REPL provides a way to interactively run
|
includable in other programs. REPL provides a way to interactively run
|
||||||
JavaScript and see the results. It can be used for debugging, testing, or
|
JavaScript and see the results. It can be used for debugging, testing, or
|
||||||
just trying things out.
|
just trying things out.
|
||||||
|
|
||||||
The standalone REPL is called `node-repl` and is installed at
|
By executing `node` without any arguments from the command-line you will be
|
||||||
`$PREFIX/bin/node-repl`.
|
dropped into the REPL. It has simplistic emacs line-editting.
|
||||||
|
|
||||||
mjr:~$ /usr/local/bin/node-repl
|
mjr:~$ node
|
||||||
Welcome to the Node.js REPL.
|
|
||||||
Enter ECMAScript at the prompt.
|
|
||||||
Tip 1: Use 'rlwrap node-repl' for a better interface
|
|
||||||
Tip 2: Type Control-D to exit.
|
|
||||||
Type '.help' for options.
|
Type '.help' for options.
|
||||||
node> a = [ 1, 2, 3];
|
node> a = [ 1, 2, 3];
|
||||||
[ 1, 2, 3 ]
|
[ 1, 2, 3 ]
|
||||||
@ -2785,6 +2782,13 @@ The standalone REPL is called `node-repl` and is installed at
|
|||||||
2
|
2
|
||||||
3
|
3
|
||||||
|
|
||||||
|
For advanced line-editors, start node with the environmental variable `NODE_NO_READLINE=1`.
|
||||||
|
This will start the REPL in canonical terminal settings which will allow you to use with `rlwrap`.
|
||||||
|
|
||||||
|
For example, you could add this to your bashrc file:
|
||||||
|
|
||||||
|
alias node="env NODE_NO_READLINE=1 rlwrap node"
|
||||||
|
|
||||||
|
|
||||||
### repl.start(prompt, stream)
|
### repl.start(prompt, stream)
|
||||||
|
|
||||||
@ -2824,28 +2828,6 @@ By starting a REPL from a Unix socket-based server instead of stdin, you can
|
|||||||
connect to a long-running node process without restarting it.
|
connect to a long-running node process without restarting it.
|
||||||
|
|
||||||
|
|
||||||
### readline support
|
|
||||||
|
|
||||||
Interactive command history for REPL is available from external programs like `rlwrap`
|
|
||||||
or `socat`. These programs are available from many Unix package managers.
|
|
||||||
|
|
||||||
To start the standalone REPL with `rlwrap`:
|
|
||||||
|
|
||||||
rlwrap node-repl
|
|
||||||
|
|
||||||
It might be convenient to use this alias in your shell configuration:
|
|
||||||
|
|
||||||
alias repl='rlwrap node-repl'
|
|
||||||
|
|
||||||
Using `socat` to connect to a Unix socket:
|
|
||||||
|
|
||||||
socat READLINE UNIX-CONNECT:/tmp/node-repl-sock
|
|
||||||
|
|
||||||
Using `socat` to connect to a TCP socket on localhost:
|
|
||||||
|
|
||||||
socat READLINE TCP-CONNECT:localhost:5001
|
|
||||||
|
|
||||||
|
|
||||||
### REPL Features
|
### REPL Features
|
||||||
|
|
||||||
Inside the REPL, Control+D will exit. Multi-line expressions can be input.
|
Inside the REPL, Control+D will exit. Multi-line expressions can be input.
|
||||||
|
@ -9,29 +9,34 @@ var kBufSize = 10*1024;
|
|||||||
|
|
||||||
|
|
||||||
var Buffer = require('buffer').Buffer;
|
var Buffer = require('buffer').Buffer;
|
||||||
|
var sys = require('sys');
|
||||||
var inherits = require('sys').inherits;
|
var inherits = require('sys').inherits;
|
||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
var stdio = process.binding('stdio');
|
var stdio = process.binding('stdio');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
exports.createInterface = function (output, isTTY) {
|
exports.createInterface = function (output) {
|
||||||
return new Interface(output, isTTY);
|
return new Interface(output);
|
||||||
};
|
};
|
||||||
|
|
||||||
function Interface (output, isTTY) {
|
function Interface (output) {
|
||||||
this.output = output;
|
this.output = output;
|
||||||
|
|
||||||
this.setPrompt("node> ");
|
this.setPrompt("node> ");
|
||||||
|
|
||||||
// Current line
|
this._tty = output.fd < 3;
|
||||||
this.line = ""
|
|
||||||
|
|
||||||
if (!isTTY) {
|
if (parseInt(process.env['NODE_NO_READLINE'])) {
|
||||||
this._tty = false;
|
this._tty = false;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if (this._tty) {
|
||||||
// input refers to stdin
|
// input refers to stdin
|
||||||
|
|
||||||
|
// Current line
|
||||||
|
this.line = "";
|
||||||
|
|
||||||
// Check process.env.TERM ?
|
// Check process.env.TERM ?
|
||||||
stdio.setRawMode(true);
|
stdio.setRawMode(true);
|
||||||
this._tty = true;
|
this._tty = true;
|
||||||
|
@ -45,8 +45,7 @@ function REPLServer(prompt, stream) {
|
|||||||
self.stream = stream || process.openStdin();
|
self.stream = stream || process.openStdin();
|
||||||
self.prompt = prompt || "node> ";
|
self.prompt = prompt || "node> ";
|
||||||
|
|
||||||
var isTTY = (self.stream.fd < 3);
|
var rli = self.rli = rl.createInterface(self.stream);
|
||||||
var rli = self.rli = rl.createInterface(self.stream, isTTY);
|
|
||||||
rli.setPrompt(self.prompt);
|
rli.setPrompt(self.prompt);
|
||||||
|
|
||||||
self.stream.addListener("data", function (chunk) {
|
self.stream.addListener("data", function (chunk) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user