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

util: add more predefined color codes to inspect.colors #30659

Closed
wants to merge 5 commits into from

Conversation

BridgeAR
Copy link
Member

  1. commit: util: improve inspect's customInspect performance
This improves the performance to copy user options that are then
passed through to the custom inspect function.

The performance improvement depends on the complexity of the custom
inspect function. For very basic cases this is 100% faster than
before.
  1. commit: util: add more predefined color codes to inspect.colors
This adds most commonly used ANSI color codes to
`util.inspect.colors`.

@nodejs/util PTAL

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

This improves the performance to copy user options that are then
passed through to the custom inspect function.

The performance improvement depends on the complexity of the custom
inspect function. For very basic cases this is 100% faster than
before.
This adds most commonly used ANSI color codes to
`util.inspect.colors`.
@nodejs-github-bot nodejs-github-bot added the util Issues and PRs related to the built-in util module. label Nov 26, 2019
@nodejs-github-bot

This comment has been minimized.

doc/api/util.md Outdated Show resolved Hide resolved
@Trott Trott added the semver-minor PRs that contain new features and should be released in the next minor version. label Nov 26, 2019
@Trott
Copy link
Member

Trott commented Nov 26, 2019

I'd consider adding more colors that we support to be semver-minor. Once we add it, we'll risk breaking people's stuff if we ever take it away.

Not strongly opposed (at least at this moment), but wondering if we might want to leave robust color support to userland modules and just support the relatively small number of colors we already support. Is there a justification for these colors in particular over the colors that we already have?

@BridgeAR
Copy link
Member Author

BridgeAR commented Nov 26, 2019

@Trott I actually already have follow-up pull requests that add further "robust" color support to Node.js.

This is just a first step in that direction. I recently had another PR open (#29676) where I needed a color code that we did not yet have in our predefined ones. We also need more APIs to properly handle colors internally. Otherwise it's not possible to add colors in Node.js core and that is something I try to slowly move forward.

@nodejs-github-bot

This comment has been minimized.

@BridgeAR BridgeAR added the performance Issues and PRs related to the performance of Node.js. label Nov 26, 2019
@nodejs-github-bot
Copy link
Collaborator

});
}

defineColorAlias('gray', 'grey');
Copy link
Member

Choose a reason for hiding this comment

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

grey/gray seem motivated, but why are the rest of these here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Mainly due to different descriptions depending on where these ANSI codes are described. I have no strong opinion on either of these names. I thought it does not hurt to allow different aliases so people could use what ever they feel most comfortable with. The camel case and all lower cased versions are just there to prevent typos.

@nodejs-github-bot
Copy link
Collaborator

@BridgeAR
Copy link
Member Author

BridgeAR commented Dec 3, 2019

@nodejs/util this could use another review :)

@BridgeAR
Copy link
Member Author

BridgeAR commented Dec 6, 2019

@nodejs/util @nodejs/repl @devsnek @Trott I would like to land this soon. I have multiple PRs that need more color support.

I'll land this if there's no objection in the next 24 hours.

lib/internal/util/inspect.js Show resolved Hide resolved
Copy link
Contributor

@antsmartian antsmartian left a comment

Choose a reason for hiding this comment

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

LGTM

@nodejs-github-bot

This comment has been minimized.

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Dec 6, 2019
@nodejs-github-bot
Copy link
Collaborator

nodejs-github-bot commented Dec 6, 2019

BridgeAR added a commit that referenced this pull request Dec 6, 2019
This improves the performance to copy user options that are then
passed through to the custom inspect function.

The performance improvement depends on the complexity of the custom
inspect function. For very basic cases this is 100% faster than
before.

PR-URL: #30659
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Anto Aravinth <[email protected]>
BridgeAR added a commit that referenced this pull request Dec 6, 2019
This adds most commonly used ANSI color codes to
`util.inspect.colors`.

PR-URL: #30659
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Anto Aravinth <[email protected]>
@BridgeAR
Copy link
Member Author

BridgeAR commented Dec 6, 2019

Landed in 2a0ec9c, 832290a 🎉

@BridgeAR BridgeAR closed this Dec 6, 2019
targos pushed a commit that referenced this pull request Dec 9, 2019
This improves the performance to copy user options that are then
passed through to the custom inspect function.

The performance improvement depends on the complexity of the custom
inspect function. For very basic cases this is 100% faster than
before.

PR-URL: #30659
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Anto Aravinth <[email protected]>
targos pushed a commit that referenced this pull request Dec 9, 2019
This adds most commonly used ANSI color codes to
`util.inspect.colors`.

PR-URL: #30659
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Anto Aravinth <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Dec 13, 2019
targos pushed a commit that referenced this pull request Jan 14, 2020
This improves the performance to copy user options that are then
passed through to the custom inspect function.

The performance improvement depends on the complexity of the custom
inspect function. For very basic cases this is 100% faster than
before.

PR-URL: #30659
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Anto Aravinth <[email protected]>
targos pushed a commit that referenced this pull request Jan 14, 2020
This adds most commonly used ANSI color codes to
`util.inspect.colors`.

PR-URL: #30659
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Anto Aravinth <[email protected]>
@BridgeAR BridgeAR deleted the improve-user-options-perf branch January 20, 2020 12:07
BethGriggs pushed a commit that referenced this pull request Feb 6, 2020
This improves the performance to copy user options that are then
passed through to the custom inspect function.

The performance improvement depends on the complexity of the custom
inspect function. For very basic cases this is 100% faster than
before.

PR-URL: #30659
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Anto Aravinth <[email protected]>
BethGriggs pushed a commit that referenced this pull request Feb 6, 2020
This adds most commonly used ANSI color codes to
`util.inspect.colors`.

PR-URL: #30659
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Anto Aravinth <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Feb 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. performance Issues and PRs related to the performance of Node.js. semver-minor PRs that contain new features and should be released in the next minor version. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants