unist-util-inspect icon indicating copy to clipboard operation
unist-util-inspect copied to clipboard

add optional `colors: boolean` flag to `Options`

Open rwe opened this issue 2 years ago • 3 comments

Initial checklist

  • [x] I read the support docs
  • [x] I read the contributing guide
  • [x] I agree to follow the code of conduct
  • [x] I searched issues and couldn’t find anything (or linked relevant results below)
  • [x] If applicable, I’ve added docs and tests

Description of changes

Previously, inspect() would always add ANSI color sequences when on Node and always omit them otherwise. inspectNoColor() and inspectColor() were exported to override this, but that was a little bit clunky. This adds an optional colors: boolean flag to Options. (Note that this is the same flag name as in node:util's inspect).

The default behaviour is unchanged: this feature is purely additive.

Internally, this also introduces the colorization/stylization functions to State, allowing the no-color path to simply omit colorization, rather than stripping ANSI sequences after the fact.

rwe avatar Sep 24 '23 19:09 rwe

Rebased to resolve the trivial import-name conflict.

rwe avatar Sep 25 '23 18:09 rwe

Thanks! It's not urgent, just some tinkering I felt might be useful to contribute.

For a little context where I was going with this before getting distracted-from-distractions, was to add a "depth" parameter and then use inspect from node:util instead of JSON.stringify in that environment. That would have been impossible or at least brittle with the post-format color erasure.

rwe avatar Oct 04 '23 20:10 rwe

Thanks for your patience!

but that was a little bit clunky

If we’re getting more options, sure.

For a little context where I was going with this before getting distracted-from-distractions, was to add a "depth" parameter and then use inspect from node:util instead of JSON.stringify in that environment. That would have been impossible or at least brittle with the post-format color erasure.

Oh nice!


Hmm, I also feel the plural colors is not needed, color: boolean is what we use everywhere. unifiedjs/unified-engine, vfile/vfile-reporter. There’s something to say for consistency with node:util, but I’d prefer consistency with our stuff.


This needs docs!

wooorm avatar Oct 26 '23 13:10 wooorm

Hi! This was closed. Team: If this was merged, please describe when this is likely to be released. Otherwise, please add one of the no/* labels.

github-actions[bot] avatar Jul 16 '24 12:07 github-actions[bot]