^c to get out of '...' in REPL
This commit is contained in:
Родитель
42eb5a6898
Коммит
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");
|
||||
this.close();
|
||||
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
|
||||
|
|
18
lib/repl.js
18
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);
|
||||
});
|
||||
|
@ -136,7 +148,7 @@ exports.start = function (prompt, source) {
|
|||
};
|
||||
|
||||
REPLServer.prototype.displayPrompt = function () {
|
||||
this.rli.setPrompt(this.buffered_cmd.length ? '... ' : this.prompt);
|
||||
this.rli.setPrompt(this.buffered_cmd.length ? '... ' : this.prompt);
|
||||
this.rli.prompt();
|
||||
};
|
||||
|
||||
|
@ -386,7 +398,8 @@ REPLServer.prototype.parseREPLKeyword = function (cmd) {
|
|||
var self = this;
|
||||
|
||||
switch (cmd) {
|
||||
case ".break":
|
||||
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");
|
||||
|
|
Загрузка…
Ссылка в новой задаче