Skip to content

repl: improve .help - #8519

Closed
silverwind wants to merge 3 commits into
nodejs:masterfrom
silverwind:repl-help-dots
Closed

repl: improve .help#8519
silverwind wants to merge 3 commits into
nodejs:masterfrom
silverwind:repl-help-dots

Conversation

@silverwind

@silverwindsilverwind commented Sep 13, 2016

Copy link
Copy Markdown
Contributor
Checklist
  • make -j4 test (UNIX), or vcbuild test nosign (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

repl

Description of change
  • Added dots to .help print
  • Use spaces instead of tabs so there's no misalignment on terminals with a tab size other than 4
  • Fixed the help text for .editor

Before:

> .help
break Sometimes you get stuck, this gets you out
clear Alias for .break
editor Entering editor mode (^D to finish, ^C to cancel)
exit Exit the repl
help Show repl options
load Load JS from a file into the REPL session
save Save all evaluated commands in this REPL session to a file

After:

> .help
.break Sometimes you get stuck, this gets you out
.clear Alias for .break
.editor Enter editor mode
.exit Exit the repl
.help Show repl options
.load Load JS from a file into the REPL session
.save Save all evaluated commands in this REPL session to a file

@silverwindsilverwind added the repl Issues and PRs related to the REPL subsystem. label Sep 13, 2016
Comment threadlib/repl.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

' '.repeat(9 - name.length)?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yep

@addaleax

Copy link
Copy Markdown
Member

I found the (^D to finish, ^C to cancel) bit helpful, especially given that @princejwesley is planning on removing “normal” multiline support?

@silverwind

Copy link
Copy Markdown
ContributorAuthor

I find it a bit redundant there, especially because .editor prints it at the start anyways.

@addaleax

Copy link
Copy Markdown
Member

… good point, I should probably get used to having to do .editor. ;)

LGTM

Comment threadlib/repl.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wait, doesn't it fail?

> ' '.repeat(-1)
RangeError: Invalid count value

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yes, it will fail once we add a command with more than 10 characters. The longest right now is editor. Do you think that warrants a safeguard for future additions?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Oh, I see that should actually be 9 - name.length. Fixing that.

@silverwind

silverwind commented Sep 13, 2016

Copy link
Copy Markdown
ContributorAuthor

CI: https://ci.nodejs.org/job/node-test-pull-request/4030/

@princejwesley noticed you print

// Entering editor mode (^D to finish, ^C to cancel)

at the start of editor mode. Would you object to me changing it to

(Entering editor mode, press ^D to finish, ^C to cancel)

so it's more in line with the ^C message?

(To exit, press ^C again or type .exit)

@princejwesley

Copy link
Copy Markdown
Contributor

@silverwind IMHO, // creates the feel that we are already in js editor.

@silverwind

Copy link
Copy Markdown
ContributorAuthor

@princejwesley

Copy link
Copy Markdown
Contributor

@silverwind For the .help description, why not just print this help message, print this summary or show this message ?

Comment threadlib/repl.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If the length is equal to 9, then there will be no space. Why not just

constspaces=' '.repeat(Math.max(9-name.length,1));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@silverwind Find the max length programmatically. User defined commands may have bigger name 😄

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Eh, I guess why not :)

- Added dots to printed commands
- Use spaces instead of tabs so there's no misalignment on terminals
with a tab size other than 4
- Improved the help text for .editor and .help
PR-URL: nodejs#8519
@silverwind

Copy link
Copy Markdown
ContributorAuthor

@princejwesley, @thefourtheye done and done

Also fixed a test. New CI: https://ci.nodejs.org/job/node-test-pull-request/4032/

@princejwesley

Copy link
Copy Markdown
Contributor

@silverwind I think you missed my last comment. User defined commands may have bigger name. find the max length programmatically.

@silverwind

silverwind commented Sep 13, 2016

Copy link
Copy Markdown
ContributorAuthor

@princejwesley Done. The amount of spaces is now calculated based on the longest command, ensuring a minimum of three spaces.

Comment threadlib/repl.js
@@ -1262,7 +1262,7 @@ function defineDefaultCommands(repl) {
const names = Object.keys(this.commands).sort();
const longestNameLength = names.reduce((max, name) => {
return Math.max(max, name.length);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@silverwind(max, name) => Math.max(max, name.length) ? is it against style guide?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

It's not, but it won't fit on 80 chars so I went with the longer form.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not named function? Feel free to ignore it

constmaxFun=(max,name)=>Math.max(max,name.length);constlongestNameLength=names.reduce(maxFun,0);

or

constnameLengthList=names.map((n)=>n.length);constlongestNameLength=nameLengthList.reduce(Math.max,0);

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

TBH, I find that these reduce readability as compared to what I have now.

@jasnelljasnell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@princejwesley

Copy link
Copy Markdown
Contributor

LGTM. I like this new github interface

@imyllerimyller left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

silverwind added a commit that referenced this pull request Sep 16, 2016
- Added dots to printed commands.
- Use spaces instead of tabs so there's no misalignment on terminals
with a tab size other than 4.
- Improved the help text for .editor and .help.
- Automatically indent command help based on the longest command.
PR-URL: #8519
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
@silverwind

Copy link
Copy Markdown
ContributorAuthor

Thanks, landed in 39fbb5a.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

replIssues and PRs related to the REPL subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@silverwind@addaleax@princejwesley@jasnell@thefourtheye@imyller@MylesBorins