Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-131952: Add color to the json CLI#132126
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
tomasr8 commented Apr 5, 2025 • edited by bedevere-app bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by bedevere-app bot
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
StanFromIreland left a comment
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.
How much of a performance impact does this have?
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
picnixz commented Apr 5, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
It doesn't matter here. |
tomasr8 commented Apr 5, 2025
I think we might not need that, |
json.tool CLI.json.tool CLIpicnixz commented Apr 5, 2025
What about CLIs? they would be broken if data is piped? |
tomasr8 commented Apr 5, 2025
AFAIU they wouldn't (and local testing confirms that), see this comment from Hugo: #131952 (comment) |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
raztd commented Apr 6, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@tomasr8 thank you for taking the time to look into it. couple of notes regarding the keys 1) could you make them a different color from the string values? 2) could you make them bold? this is what jq does and i think it provides a good ux https://static1.howtogeekimages.com/wordpress/wp-content/uploads/2020/01/5-7.png |
tomasr8 commented Apr 6, 2025
That should be in theory possible, we can distinguish keys from string literals since keys are always followed by |
Lib/json/tool.py Outdated
| with_colors = can_colorize() | ||
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.
This variable isn't doing much, shall we just call the function directly?
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 may have been too cautious here. Without the variable, the function would be called in a loop and I was worried the result could change in between invocations, though that is really unlikely. If you prefer I can remove it?
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.
Actually, I applied your other suggestion which already removed it so never mind 😄
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.
No, that's a good point: there could be a lot of objs as JSONL files can be quite long. Let's add with_colors back, but just outside the loop.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
tomasr8 commented Apr 15, 2025
AA-Turner commented Apr 15, 2025
The green and cyan colours here look bad on the white background, which is the default for Windows Terminal, PyCharm's in-built terminal, etc. Could you darken them? |
tomasr8 commented Apr 15, 2025
AA-Turner commented Apr 15, 2025
I also prefer the bold version, thanks. A |
tomasr8 commented Apr 15, 2025
Thanks for your feedback! I think it looks much better now :) I added the bold colors and updated tests. Would you mind taking another look? |
raztd commented Apr 16, 2025
i like the colors. one small request: could you bold the keys and leave the values regular? that's how jq does it https://static1.howtogeekimages.com/wordpress/wp-content/uploads/2020/01/5-7.png |
tomasr8 commented Apr 16, 2025
I think I prefer the bold colors. In my opinion, they are more legible when bold, especially with the light theme. |
raztd commented Apr 16, 2025
in the last pair of screenshots, i see only the values as bold. the keys look regular. my proposal was to invert those. or do you want to make the keys bold, too? i think that could work |
AA-Turner left a comment
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!
A
Uh oh!
There was an error while loading. Please reload this page.
hugovk commented Apr 17, 2025
hugovk commented Apr 17, 2025
Please could you also add this to What's New, and mention the colour env vars, like the other similar entries? |
tomasr8 commented Apr 19, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Adam Turner <[email protected]>
tomasr8 commented Apr 19, 2025
Added - I reused your entry from the calendar module ;) |
hugovk left a comment
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.
Thank you! 🎨
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Stan Ulbrych <[email protected]>
71da68d into python:mainUh oh!
There was an error while loading. Please reload this page.
















Example:
I'm open to changing the colors. For now it's green for strings, yellow for numbers and cyan for true/false/null.