Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repl: Proposal for better repl (implementation) #9601

Closed
wants to merge 7 commits into from

Conversation

princejwesley
Copy link
Contributor

@princejwesley princejwesley commented Nov 14, 2016

Checklist
  • make -j4 test (UNIX), or vcbuild test nosign (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

repl

Description of change
  • Welcome message with version and help guide
    • displayWelcomeMessage flag is used to
      turn on/off
  • Differentiate execute & continue actions
    • ^M or enter key to execute the command
    • ^J to continue building multiline expression.
    • executeOnTimeout value is used to determine
      the end of expression when terminal is false.
  • Pretty stack trace.
    • REPL specific stack frames are removed before
      emitting to output stream.
  • Recoverable errors.
    • No more recoverable errors & no false positives.
  • Defined commands(like .exit, .load)
    • Meaningful only at the top level.
    • .break is removed - no more get stuck

Welcome message template

$ node
Welcome to Node.js <<version>> (<<vm name>> VM, <<vm version>>)
Type ^M or enter to execute, ^J to continue, ^C to exit
Or try .help for help, more at https://nodejs.org/dist/<<version>>/docs/api/repl.html

>

Pretty stack trace

$ node -i
> throw new Error('tiny stack')
Error: tiny stack
    at repl:1:7
> var x y;
var x y;
      ^
SyntaxError: Unexpected identifier
>

Refs: #8195
Original WIP PR: #8504

@nodejs-github-bot nodejs-github-bot added debugger readline Issues and PRs related to the built-in readline module. repl Issues and PRs related to the REPL subsystem. labels Nov 14, 2016
@jasnell
Copy link
Member

jasnell commented Nov 18, 2016

@princejwesley +1 on this... it's going to take some time to review properly tho. Will hopefully have some comments soon

@jasnell jasnell added the semver-major PRs that contain breaking changes and should be released in the next major version. label Nov 18, 2016
@jasnell jasnell added the stalled Issues and PRs that are stalled. label Mar 24, 2017
@fhinkel
Copy link
Member

fhinkel commented Mar 26, 2017

@princejwesley Would it make sense to rebase this?

@princejwesley
Copy link
Contributor Author

@fhinkel sure, I'll do

* Welcome message with version and help guide
    * `displayWelcomeMessage` flag is used to
      turn on/off
* Differentiate execute & continue actions
    * ^M or enter key to execute the command
    * ^J to continue building multiline expression.
    * `executeOnTimeout` value is used to determine
      the end of expression when `terminal` is false.
* Pretty stack trace.
    * REPL specific stack frames are removed before
      emitting to output stream.
* Recoverable errors.
    * No more recoverable errors & no false positives.
* Defined commands(like .exit, .load) are meaningful
  only at the top level.
* Remove `.break` command.

Welcome message template
------------------------
```js
$ node
Welcome to Node.js <<version>> (<<vm name>> VM, <<vm version>>)
Type ^M or enter to execute, ^J to continue, ^C to exit
Or try

```

Pretty stack trace
------------------
```js
$ node -i
> throw new Error('tiny stack')
Error: tiny stack
    at repl:1:7
> var x y;
var x y;
      ^
SyntaxError: Unexpected identifier
>
```
@princejwesley
Copy link
Contributor Author

@princejwesley princejwesley removed the stalled Issues and PRs that are stalled. label Apr 2, 2017
lib/repl.js Outdated
self.displayPrompt();
}
inherits(REPLServer, Interface);
exports.REPLServer = REPLServer;

exports.REPL_MODE_SLOPPY = Symbol('repl-sloppy');
exports.REPL_MODE_STRICT = Symbol('repl-strict');
exports.REPL_MODE_MAGIC = exports.REPL_MODE_SLOPPY;
exports.REPL_MODE_MAGIC = Symbol('repl-strict');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this change intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope!

lib/repl.js Outdated
const docURL = `https://nodejs.org/dist/${version}/docs/api/repl.html`;

const welcome = `Welcome to Node.js ${version} (${jsEngine} VM,` +
` ${jsEngineVersion})\nType ^M or enter to execute,` +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Node.js ${version} (${jsEngine} ${jsEngineVersion}) should suffice; the "VM" seems a bit extraneous.

lib/repl.js Outdated
magic.context = magic.createContext();
flat.run(tmp); // eval the flattened code
flat.run(tmp, magic); // eval the flattened code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment indentation is now out of date.

lib/repl.js Outdated
@@ -1224,6 +1253,32 @@ function regexpEscape(s) {
}


function indexOfInternalFrame(frames) {
return frames.indexOf('vm.js') !== -1 ||
frames.indexOf('REPLServer.') !== -1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this interfere with userland script files named vm.js?

lib/repl.js Outdated
}
inherits(Recoverable, SyntaxError);
exports.Recoverable = Recoverable;
}, 'replServer.convertToContext() is deprecated');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DEP0024 code was removed accidentally.

doc/api/repl.md Outdated
displayed. Defaults to `false`.
```js
> node
Welcome to Node.js <<version>> (<<vm name>> VM, <<vm version>>)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The VM should be gone now.

doc/api/repl.md Outdated
@@ -440,11 +420,15 @@ without passing any arguments (or by passing the `-i` argument):

```js
$ node
> const a = [1, 2, 3];
Welcome to Node.js v6.5.0 (v8 VM, 5.1.281.81)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

lib/repl.js Outdated
this.run = function(data) {
for (var n = 0; n < data.length; n++)
this.emit('data', `${data[n]}\n`);
this.run = (data, repl) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this function be put into the prototype object?

@@ -56,7 +52,7 @@ welcome('Node.js User');

The following key combinations in the REPL have these special effects:

* `<ctrl>-C` - When pressed once, has the same effect as the `.break` command.
* `<ctrl>-C` - When pressed once, it will break the current command.
When pressed twice on a blank line, has the same effect as the `.exit`
command.
* `<ctrl>-D` - Has the same effect as the `.exit` command.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^M and ^J should be documented.

@@ -178,34 +174,6 @@ function myEval(cmd, context, filename, callback) {
repl.start({prompt: '> ', eval: myEval});
```

#### Recoverable Errors
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I for one am not very happy this feature got removed. In recent versions of Chrome, a similar function just got added (instead of having to type Shift+Enter, the prompt automatically recognizes line continuation), and to have to type an awkward Ctrl+J for the same feature does not sound very appealing to me.

If this change is here to stay, may I suggest we at least add support to Shift+Enter also/instead? It is the syntax in most IM apps, and also in most developer consoles.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TimothyGu we discussed this option here. Shift+Enter is not possible

@TimothyGu TimothyGu dismissed their stale review April 3, 2017 07:43

Comments addressed

@BridgeAR
Copy link
Member

Ping @princejwesley this needs a rebase. Do you still want to follow up on this?

@princejwesley
Copy link
Contributor Author

@BridgeAR @TimothyGu point is valid, it will force user to use extra control key to execute or continue.

@lance
Copy link
Member

lance commented Sep 6, 2017

@princejwesley @BridgeAR @TimothyGu

This PR is comprised of a lot of incremental improvements. Some of these are still somewhat controversial. In order to move forward with some of the items that are universally agreed on (e.g. better stack traces and improved welcome message), would it perhaps be better and more fruitful in the short term to submit those as individual PRs? @princejwesley if you are not opposed, I could take a look at this.

@TimothyGu
Copy link
Member

@lance Agreed.

@princejwesley
Copy link
Contributor Author

@lance sure

@lance
Copy link
Member

lance commented Sep 14, 2017

Due to the various reasons noted above, I'm closing this PR. Feel free to reopen if you would like to continue work on it.

@lance lance closed this Sep 14, 2017
lance added a commit that referenced this pull request Oct 11, 2017
When a user executes code in the REPLServer which generates an
exception, there is no need to display the REPLServer internal
stack frames.

PR-URL: #15351
Reviewed-By: Prince John Wesley <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>

Refs: #9601
addaleax pushed a commit to addaleax/ayo that referenced this pull request Oct 12, 2017
When a user executes code in the REPLServer which generates an
exception, there is no need to display the REPLServer internal
stack frames.

PR-URL: nodejs/node#15351
Reviewed-By: Prince John Wesley <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>

Refs: nodejs/node#9601
gibfahn pushed a commit that referenced this pull request Dec 20, 2017
When a user executes code in the REPLServer which generates an
exception, there is no need to display the REPLServer internal
stack frames.

PR-URL: #15351
Backport-PR-URL: #16457
Reviewed-By: Prince John Wesley <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>

Refs: #9601
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
readline Issues and PRs related to the built-in readline module. repl Issues and PRs related to the REPL subsystem. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants