Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2010-09-17 08:07:22 +0400
committerRyan Dahl <ry@tinyclouds.org>2010-09-17 22:23:08 +0400
commitbcbc52e257976592bcc41a12b412a26097f7f40c (patch)
tree6bacfb15799bfe7bb5eb166b2f3b8543304ca3b1
parentc00a6a7169d6d7eaa50cdae0b638a3af004e575f (diff)
^c to get out of '...' in REPL
-rw-r--r--lib/readline.js12
-rw-r--r--lib/repl.js18
2 files changed, 25 insertions, 5 deletions
diff --git a/lib/readline.js b/lib/readline.js
index f6d6034983a..3270e12bf50 100644
--- a/lib/readline.js
+++ b/lib/readline.js
@@ -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
diff --git a/lib/repl.js b/lib/repl.js
index 6f9c01901d7..e4b8a1797ba 100644
--- a/lib/repl.js
+++ b/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");