-
Notifications
You must be signed in to change notification settings - Fork 15
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
Format json with JQ_COLORS
#14
Conversation
tojson/1 is not defined by jq or gojq
Commit 231277f moves |
jqjq.jq
Outdated
end; | ||
( [_f] | ||
| add | ||
); | ||
|
||
# get the ANSI color codes for printing values | ||
# corresponds to jv_set_colors and its usage in main | ||
def parse_colors($opts; $env): |
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.
fq lacks JQ_COLORS
support atm (has it's own color config with more stuff) maybe can steal some of this code :)
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.
You're welcome to use it for that :). It should represent the C parsing and formatting exactly.
From my tests, it appears the gojq ignores JQ_COLORS
and it formats differently. Maybe it would be worth coordinating a decision with gojq? I figure you probably inherited that from using gojq as a library.
I submitted jqlang/jq#3034, which fixes some usually-invisible inconsistencies with colors in jq. I think that should be merged regardless, but in addition it might worth bringing jq more into line with gojq. In particular, I don't really like how in jq, {
, :
, ,
, and }
in objects get the object color and [
, ,
, and ]
in arrays get the array color. I think :
and ,
punctuation should be colored uniformly across objects and arrays. Personally, I don't see much use in coloring braces and brackets, but many people like coloring them by nesting depth in VS Code, so I can see why this simplistic differentiation could be somewhat useful.
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.
You're welcome to use it for that :). It should represent the C parsing and formatting exactly.
👍
From my tests, it appears the gojq ignores
JQ_COLORS
and it formats differently. Maybe it would be worth coordinating a decision with gojq? I figure you probably inherited that from using gojq as a library.
Kind-of, fq uses a modified version of cli/encoder.go from gojq https://github.com/wader/fq/blob/master/internal/colorjson/encoder.go that makes the options non-global and adds some things needed by fq (how to format binary strings etc)
I noticed now that gojq seems to only read GOJQ_COLORS
, was thinking if i added support in fq i would probably read FQ_COLORS
and fallback to JQ_COLORS
? hmm
I submitted jqlang/jq#3034, which fixes some usually-invisible inconsistencies with colors in jq. I think that should be merged regardless, but in addition it might worth bringing jq more into line with gojq. In particular, I don't really like how in jq,
{
,:
,,
, and}
in objects get the object color and[
,,
, and]
in arrays get the array color. I think:
and,
punctuation should be colored uniformly across objects and arrays. Personally, I don't see much use in coloring braces and brackets, but many people like coloring them by nesting depth in VS Code, so I can see why this simplistic differentiation could be somewhat useful.
I see, hmm haven't really thought about it much so no string opinion, but making them more consistent make sense i think. Let's see what the other maintainers think
👍 |
Thanks for the review! I'll go through your comments in the morning. Shortly after your review, I implemented the raw output options, which I've now pushed. They touch the This reduces the missing features needed for wsjq even more! |
No stress!
Either way works for me so let's keep it here
🥳 |
Updates to match the changes in jqlang/jq#3034.
Since jqlang/jq#3034 looks like it'll be merged, I've pushed a commit to match it. |
- [x] Run jqjq with jqjq | ||
- [x] Bugs | ||
|
||
### jq's test suite | ||
|
||
``` | ||
```sh |
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.
I tried to rerun this, still 307, but i did notice that something seems strange with the output when running tests. Have a look at make test
guessing it's the switch to --join-output
that require some change?
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.
I just changed ./jqjq
to replace --join-output
with --raw-output
for --run-tests
.
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.
I get 308 on jq.test
from jq origin/main.
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.
Huh made sure i had master also now, still 307, weird, some locale thing? anyways, that's for another time
BTW talking about ANSI output, maybe https://github.com/wader/ansisvg is interesting? think my main use of it has been producing colorful output from jq and fq for presentations :) |
So ready to merge? |
Yep! |
Great work! and so happy someone else wants to help out with this weird thing :) |
Hmm noticed |
Your ansisvg project looks useful. I've used asciinema for that kind of thing before, but this would be usable outside the browser when it's not animated. It reminds me of a tiny project I did, terminal-palette. It computes the nearest color in a palette for RGB colors, by using the perceptual distance between colors in the CIELAB color space (logic borrowed from james-oldfield/nearest-colour). I used it to make fallback color schemes for my Tetris game, programmed in Whitespace. It uses the official piece colors when the terminal supports 24-bit color, or uses similar colors from the 256 colors if that's supported, or otherwise uses the basic 16 colors. |
Neat! think i will have to have a closer look at the whitespace language |
Getter a bit late here, feel tree to merge a fix for help if you look into it. Otherwise will fix or review tomorrow |
Good catch for In this case, the fix is to add |
Nice, yeap push is fine too! |
This PR adds support for colors via
JQ_COLORS
and enabling/disabling withNO_COLORS
,--color-output
/-C
, and--monochrome-output
/-M
. The formatting matches jq (not gojq).I've tested this and it has identical behavior to jq. If we want to add tests, it would need a new harness, because
--run-tests
uses value-based equality, not formatted textual equality.I also removed the
tojson/1
intrinsic, because neither jq nor gojq define it.If jqlang/jq#3034 is merged, I'll update
_tojson
here to match.