Skip to content

repl: improve .help #8519

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

Closed
wants to merge 3 commits into from
Closed

Conversation

silverwind
Copy link
Contributor

@silverwind silverwind commented Sep 13, 2016

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

@silverwind silverwind added the repl Issues and PRs related to the REPL subsystem. label Sep 13, 2016
self.outputStream.write(name + '\t' + (cmd.help || '') + '\n');
Object.keys(this.commands).sort().forEach((name) => {
const cmd = this.commands[name];
const spaces = new Array(10 - name.length).join(' ');
Copy link
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
Contributor Author

Choose a reason for hiding this comment

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

Yep

@addaleax
Copy link
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
Contributor Author

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

@addaleax
Copy link
Member

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

LGTM

self.outputStream.write(name + '\t' + (cmd.help || '') + '\n');
Object.keys(this.commands).sort().forEach((name) => {
const cmd = this.commands[name];
const spaces = ' '.repeat(name.length - 9);
Copy link
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
Contributor Author

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
Contributor Author

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
Copy link
Contributor Author

silverwind commented Sep 13, 2016

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
Contributor

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

@silverwind
Copy link
Contributor Author

@princejwesley
Copy link
Contributor

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

self.outputStream.write(name + '\t' + (cmd.help || '') + '\n');
Object.keys(this.commands).sort().forEach((name) => {
const cmd = this.commands[name];
const spaces = ' '.repeat(name.length <= 9 ? 9 - name.length : 1);
Copy link
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

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

Copy link
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
Contributor Author

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
Contributor Author

@princejwesley, @thefourtheye done and done

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

@princejwesley
Copy link
Contributor

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

@silverwind
Copy link
Contributor Author

silverwind commented Sep 13, 2016

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

@@ -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
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
Contributor Author

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
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

const maxFun = (max, name) => Math.max(max, name.length);
const longestNameLength = names.reduce(maxFun, 0);

or

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

Copy link
Contributor Author

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.

Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

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

LGTM

@princejwesley
Copy link
Contributor

LGTM. I like this new github interface

Copy link
Member

@imyller imyller left a comment

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 <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Prince John Wesley <[email protected]>
Reviewed-By: Ilkka Myller <[email protected]>
@silverwind
Copy link
Contributor Author

Thanks, landed in 39fbb5a.

@silverwind silverwind closed this Sep 16, 2016
@silverwind silverwind deleted the repl-help-dots branch September 16, 2016 14:53
Fishrock123 pushed a commit that referenced this pull request Oct 11, 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 <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Prince John Wesley <[email protected]>
Reviewed-By: Ilkka Myller <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants