-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
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
repl: improve .help #8519
Conversation
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(' '); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
' '.repeat(9 - name.length)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep
I found the |
I find it a bit redundant there, especially because |
… good point, I should probably get used to having to do 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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
CI: https://ci.nodejs.org/job/node-test-pull-request/4030/ @princejwesley noticed you print
at the start of editor mode. Would you object to me changing it to
so it's more in line with the ^C message?
|
@silverwind IMHO, |
@princejwesley okay let's keep it new CI: https://ci.nodejs.org/job/node-test-pull-request/4031/ |
@silverwind For the |
213394f
to
93b3d8b
Compare
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); |
There was a problem hiding this comment.
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));
There was a problem hiding this comment.
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 😄
There was a problem hiding this comment.
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
93b3d8b
to
82afbbb
Compare
@princejwesley, @thefourtheye done and done Also fixed a test. New CI: https://ci.nodejs.org/job/node-test-pull-request/4032/ |
@silverwind I think you missed my last comment. User defined commands may have bigger name. find the max length programmatically. |
@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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LGTM. I like this new github interface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
- 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]>
Thanks, landed in 39fbb5a. |
- 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]>
Checklist
make -j4 test
(UNIX), orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
repl
Description of change
.help
print.editor
Before:
After: