Node: repl: Proposal for better repl

Created on 20 Aug 2016  路  20Comments  路  Source: nodejs/node

This is my idea/wish to address Node.js repl related issues.

  • Automatic multiline command mode has serious issues.

    • Recoverable error guess is based on error message emitted by v8(vm specific) engine

      (we may have to fix the code if vm emits different error string in next release)

    • False positives. We have to .break/^C the expression to continue.

    • We can't reliably deduce the end of expression even if we build an incremental JS parser.

js let echo = e => e; let x; x = echo(2); // 2 x = echo // both echo and echo\n(2) are completely valid expression (2) // 2

  • No welcome message (it helps to see version number)

Proposal

  • Welcome message with version and help guide
  • Differentiate execute & continue actions

    • ^M or enter key to execute the command (current behavior)

    • ^J to continue (Hand over the problem to user, let user decides it) building multiline expression.

      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/v<<version>>/docs/api/repl.html
>

e.g.

> node
Welcome to Node.js 6.4.0 (v8 VM, 5.0.71.60)
Type ^M or enter to execute, ^J to continue, ^C to exit
Or try .help for help, more at https://nodejs.org/dist/v6.4.0/docs/api/repl.html
>

@nodejs/collaborators, I am happy to implement this if there is no objection

_Note_ : Current system executes code when ^M, ^J or enter pressed. ^I or tab for code completion

discuss feature request repl

Most helpful comment

@nodejs/collaborators if there is no objection, I'll start work on it

All 20 comments

There are a consideration: introducing the combining types like ^M or ^J might be unreasonable conflict with the shell itself.

For example, in my iTerm.app, ^M would close the current window.

@yorkie Tried cmd + M or ctrl + M(^M) ? if we are in repl context, I don't see any conflict. ^M for execute command is an existing behaviour.

@princejwesley it depends on what shell you are using IMO, it doesn't work at iTerm. Let me verify it again later :)

What about just enter and shift+enter or similar for execute and continue respectively?

@yorkie I use same iTerm 馃槃 . See control characters and here

@mscdex Terminal emits same value for both shift + enter and enter.

Sorry @princejwesley you are right, it works :-)

This makes sense. I do like the idea of ^J _or_ Shift-Enter to continue. That would pair nicely with ^M _or_ Enter to execute.

@jasnell We can't capture Shift-Enter. Terminal emits same ^M for Enter and Shift-Enter(terminal ignores ctrl, shift or meta keys when paired with Enter)

~ 馃檲 鈧筤M (ctrl+v, enter)
~ 馃檲 鈧筤M (ctrl+v, shift+enter)

For me, ^J sounds like jump to next line 馃槃 .

Ok, I'm good with that then.

@nodejs/collaborators if there is no objection, I'll start work on it

What about requiring that, for an expression to be submitted, it must be followed by 2 newlines or by a semicolon?

@princejwesley Are you still working on this?

@Trott it's implemented long ago

@princejwesley You mean https://github.com/nodejs/node/pull/9601? Can you rebase against master and hopefully some of the people that +1'ed it can give it an official LGTM and we can get it landed?

@Trott sure, I'll do

Since #9601 has been closed, is there any reason for this to remain open?

If @princejwesley wants to keep working on this, I see no reason not to keep it open.

heh... that answers that then. Really do appreciate the work and effort on this @princejwesley

Well, tbh, I closed #9601 myself. But based on feedback received in that PR, and on my subsequent PRs that pick up some of that work, I think it would take a big effort for #9160 as it is to land. Hope I wasn't being premature about that.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

VanCoding picture VanCoding  路  204Comments

jonathanong picture jonathanong  路  93Comments

thecodingdude picture thecodingdude  路  158Comments

ctavan picture ctavan  路  87Comments

AkashaThorne picture AkashaThorne  路  207Comments