Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added a result history to REPL #1120

Closed
wants to merge 2 commits into from

7 participants

@pipobscure

.$ turns the history in $ on/of (toggle)

$ is an array containing the history of results. Every time a command is executed it is unshifted onto the array.

phidelta added some commits
@ry
ry commented

@isaacs, @felixge I'll leave this issue to you to decide on. I don't really care. If it does land it should go in master.

@dmmalam

+1 for this

@trevnorris
Owner

Could easily be rebased to master with a few tweaks. Anyone still want this functionality?

@Nodejs-Jenkins

Can one of the admins verify this patch?

@hackedy

If this is going to end up in master I would recommend following the chrome devtools precedent for special variable names.

@pipobscure

@hackedy which means what? Because the only relevant example in the chrome devtools page you linked was $_

Are you saying you would prefer $_ rather than just $ ?

I'll give it another shot and redo it for the current master.

@pipobscure

Redid this for current master 3b60d0a

Basically you can trigger it by doing:

$=[];

From then on the last 10 results will be in that array newest first.

Though I question whether this is even necessary considering we already have the last item in _

Can we just have a decision and close this thing?

@pipobscure

If you also want the .$ command to toggle the history the go for 516719e

@indutny indutny closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 28, 2011
  1. REPL History

    phidelta authored
  2. Fixed REPL off

    phidelta authored
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 1 deletion.
  1. +19 −1 lib/repl.js
View
20 lib/repl.js
@@ -63,6 +63,7 @@ module.paths = require('module')._nodeModulePaths(module.filename);
// Can overridden with custom print functions, such as `probe` or `eyes.js`
exports.writer = util.inspect;
+var resultCache;
function REPLServer(prompt, stream) {
var self = this;
@@ -150,7 +151,7 @@ function REPLServer(prompt, stream) {
// '{ a : 1 }'
// and statements e.g.
// 'for (var i = 0; i < 10; i++) console.log(i);'
-
+ self.context.$ = resultCache;
var ret, success = false;
try {
// First we attempt to eval as expression with parens.
@@ -169,6 +170,9 @@ function REPLServer(prompt, stream) {
}
if (ret !== undefined) {
+ if (resultCache) {
+ resultCache.unshift(ret);
+ }
self.context._ = ret;
self.outputStream.write(exports.writer(ret) + '\n');
}
@@ -546,6 +550,20 @@ function defineDefaultCommands(repl) {
this.displayPrompt();
}
});
+
+ repl.defineCommand('$', {
+ help:'Toggle the results array in $',
+ action:function() {
+ if (resultCache) {
+ resultCache = undefined;
+ this.outputStream.write('$ result array off\n');
+ } else {
+ resultCache = [];
+ this.outputStream.write('$ result array on\n');
+ }
+ this.displayPrompt();
+ }
+ });
}
Something went wrong with that request. Please try again.