^c to get out of '...' in REPL
This commit is contained in:
parent
42eb5a6898
commit
d2de8ba400
@ -20,10 +20,13 @@ exports.createInterface = function (output, completer) {
|
||||
};
|
||||
|
||||
function Interface (output, completer) {
|
||||
if (!(this instanceof Interface)) return new Interface(output, completer);
|
||||
EventEmitter.call(this);
|
||||
|
||||
this.output = output;
|
||||
this.completer = completer;
|
||||
|
||||
this.setPrompt("node> ");
|
||||
this.setPrompt("> ");
|
||||
|
||||
this.enabled = output.fd < 3; // Looks like a TTY.
|
||||
|
||||
@ -266,7 +269,12 @@ Interface.prototype._ttyWrite = function (b) {
|
||||
/* ctrl+c */
|
||||
case 3:
|
||||
//process.kill(process.pid, "SIGINT");
|
||||
if (this.listeners('SIGINT').length) {
|
||||
this.emit('SIGINT');
|
||||
} else {
|
||||
// default behavior, end the readline
|
||||
this.close();
|
||||
}
|
||||
break;
|
||||
|
||||
case 4: // control-d, delete right or EOF
|
||||
|
14
lib/repl.js
14
lib/repl.js
@ -53,14 +53,26 @@ function REPLServer(prompt, stream) {
|
||||
var rli = self.rli = rl.createInterface(self.stream, function (text) {
|
||||
return self.complete(text);
|
||||
});
|
||||
|
||||
if (rli.enabled) {
|
||||
// Turn on ANSI coloring.
|
||||
exports.writer = function(obj, showHidden, depth) {
|
||||
return sys.inspect(obj, showHidden, depth, true);
|
||||
}
|
||||
}
|
||||
|
||||
rli.setPrompt(self.prompt);
|
||||
|
||||
rli.on("SIGINT", function () {
|
||||
if (self.buffered_cmd && self.buffered_cmd.length > 0) {
|
||||
rli.write("\n");
|
||||
self.buffered_cmd = '';
|
||||
self.displayPrompt();
|
||||
} else {
|
||||
rli.close();
|
||||
}
|
||||
});
|
||||
|
||||
self.stream.addListener("data", function (chunk) {
|
||||
rli.write(chunk);
|
||||
});
|
||||
@ -387,6 +399,7 @@ REPLServer.prototype.parseREPLKeyword = function (cmd) {
|
||||
|
||||
switch (cmd) {
|
||||
case ".break":
|
||||
// TODO remove me after 0.3.x
|
||||
self.buffered_cmd = '';
|
||||
self.displayPrompt();
|
||||
return true;
|
||||
@ -400,7 +413,6 @@ REPLServer.prototype.parseREPLKeyword = function (cmd) {
|
||||
self.stream.destroy();
|
||||
return true;
|
||||
case ".help":
|
||||
self.stream.write(".break\tSometimes you get stuck in a place you can't get out... This will get you out.\n");
|
||||
self.stream.write(".clear\tBreak, and also clear the local context.\n");
|
||||
self.stream.write(".exit\tExit the prompt\n");
|
||||
self.stream.write(".help\tShow repl options\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user