Skip to content

Commit

Permalink
Simplify REPL displayPrompt
Browse files Browse the repository at this point in the history
Now that we insert \r into the stream and aren't switching back and forth
between termios modes, not need to worry about when to display the prompt.
  • Loading branch information
ry committed Nov 12, 2010
1 parent 564a486 commit 8e09b1e
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ function REPLServer(prompt, stream) {
rli.addListener('line', function (cmd) {
cmd = trimWhitespace(cmd);

var flushed = true;

// Check to see if a REPL keyword was used. If it returns true,
// display next prompt and return.
if (cmd && cmd.charAt(0) === '.') {
Expand All @@ -100,7 +98,7 @@ function REPLServer(prompt, stream) {
var ret = evalcx(self.buffered_cmd, context, "repl");
if (ret !== undefined) {
context._ = ret;
flushed = self.stream.write(exports.writer(ret) + "\n");
self.stream.write(exports.writer(ret) + "\n");
}

self.buffered_cmd = '';
Expand All @@ -113,28 +111,14 @@ function REPLServer(prompt, stream) {
} catch (e) {
// On error: Print the error and clear the buffer
if (e.stack) {
flushed = self.stream.write(e.stack + "\n");
self.stream.write(e.stack + "\n");
} else {
flushed = self.stream.write(e.toString() + "\n");
self.stream.write(e.toString() + "\n");
}
self.buffered_cmd = '';
}

// need to make sure the buffer is flushed before displaying the prompt
// again. This is really ugly. Need to have callbacks from
// net.Stream.write()
if (flushed) {
self.displayPrompt();
} else {
self.displayPromptOnDrain = true;
}
});

self.stream.addListener('drain', function () {
if (self.displayPromptOnDrain) {
self.displayPrompt();
self.displayPromptOnDrain = false;
}
self.displayPrompt();
});

rli.addListener('close', function () {
Expand Down

0 comments on commit 8e09b1e

Please sign in to comment.