-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Consistently reset color formatting #3034
Conversation
Before, arrays would not reset colors after `[` and `,`, but objects would; it would reset colors twice before `]` and `}`; and some cases of indentation would have colors applied. Now, colors are reset immediately after any token that is colored, before any indentation. This makes the formatting consistent, for the benefit of custom `JQ_COLORS`.
} > $d/expect | ||
cmp $d/color $d/expect | ||
|
||
## Set non-default colors, complex input, indented |
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.
Does this regression test verify the reset issue for arrays? i can visually see the issue using JQ_COLORS='0;30:0;31:0;32:0;33:0;34:7;35:1;36:1;37' jq -Cn '[{"a":true,"b":false},123,null]'
(7 to reverse colors for arrays)
Nice 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.
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 but let's wait for one more review
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. Thank you!
The only remaining inconsistency, is that I’ll push that fix later in the day. |
Colors have a color separate from object keys, so were not tested.
I'm all done on my end and am ready to merge. Here's a before/after recap: < ␛[1;35m[\n
> ␛[1;35m[␛[0m\n
< ␛[1;36m{\n
> ␛[1;36m{␛[0m\n
< ␛[0m␛[1;37m"a"␛[0m␛[1;36m: ␛[0m␛[0;32mtrue␛[0m␛[1;36m,\n
> ␛[1;37m"a"␛[0m␛[1;36m:␛[0m ␛[0;32mtrue␛[0m␛[1;36m,␛[0m\n
< ␛[0m␛[1;37m"b"␛[0m␛[1;36m: ␛[0m␛[0;31mfalse␛[0m␛[1;36m\n
> ␛[1;37m"b"␛[0m␛[1;36m:␛[0m ␛[0;31mfalse␛[0m\n
< ␛[1;36m}␛[0m␛[1;35m,\n
> ␛[1;36m}␛[0m␛[1;35m,␛[0m\n
< ␛[0;34m"abc"␛[0m␛[1;35m,\n
> ␛[0;34m"abc"␛[0m␛[1;35m,␛[0m\n
< ␛[0;33m123␛[0m␛[1;35m,\n
> ␛[0;33m123␛[0m␛[1;35m,␛[0m\n
< ␛[0;30mnull␛[0m␛[1;35m\n
> ␛[0;30mnull␛[0m\n
< ␛[1;35m]␛[0m\n
> ␛[1;35m]␛[0m\n Before:
After:
Generated roughly with: #!/usr/bin/env bash
set -euo pipefail
for ref in 8a9a74d ccebd8e; do
git checkout "$ref"
make -j8
mv jq "$(git describe --tags)"
done
colors() {
JQ_COLORS='0;30:0;31:0;32:0;33:0;34:1;35:1;36:1;37' \
"$1" -Cn '[{"a":true,"b":false},"abc",123,null]' |
gsed -z -e 's/\n/\\n\n/g' -e 's/\x1b/␛/g'
}
diff <(colors ./jq-1.7.1-18-g8a9a74d) \
<(colors ./jq-1.7.1-21-gccebd8e) |
Updates to match the changes in jqlang/jq#3034.
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.
👍
Thanks! |
Before, arrays would not reset colors after
[
and,
, but objects would; it would reset colors twice before]
and}
; and some cases of indentation would have colors applied. Now, colors are reset immediately after any token that is colored, before any indentation. This makes the formatting consistent, for the benefit of customJQ_COLORS
.