jwt-cli icon indicating copy to clipboard operation
jwt-cli copied to clipboard

Add syntax highlighting

Open ambiso opened this issue 2 years ago • 3 comments

Colors! Because who doesn't like them?!

Just opening this PR to see if there's demand. It's a really slow/lazy way to implement syntax highlighting but it works. I can improve the implementation if there's a need.

Summary

JSON syntax highlighting:

terminal output with JSON Token header and Token claims; the JSON values are highlighted now with color

The color turns off if the application is not outputting to a TTY:

image

Preflight checklist

  • [X] Code formatted with rustfmt
  • [ ] Relevant tests added
  • [ ] Any new documentation added

ambiso avatar Jul 12 '22 07:07 ambiso

Hey @ambiso, thanks for this, and thanks for your patience! I think this looks ok to me, although I wonder if there should be a flag to turn this off. I think it's probably ok to not have one for now unless folks start raising issues about it, but I'd like to get your thoughts.

Finally, looks like there's some cargo conflicts. If you have time, could you merge/rebase?

mike-engel avatar Oct 27 '22 20:10 mike-engel

I rewrote the changes for the latest version; I tried adding a --color=always | never | auto flag, but couldn't find a neat way to do it with clap - it has support for a ColorChoice but it doesn't look like it's easy to support this ColorChoice as a command line flag. https://docs.rs/clap/latest/clap/builder/struct.Command.html#method.color

ambiso avatar Nov 04 '22 16:11 ambiso

Thanks @ambiso! In researching a solution for #197, I realized that bunt via termcolor has support for this that we could emulate (or maybe bat supports NO_COLOR?)

mike-engel avatar Nov 04 '22 19:11 mike-engel