-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
Color output of keys and values like jq #17
Comments
You can |
I think it's still worth doing as part of yq itself, many people use It's okay if pygments is not ideal, just redirect people to their repo in case someone wants to report an issue. |
Here's the alternative I landed on, use the cli-highlight tool.
I also defined an alias for |
There have been a corresponding issue on jq: jqlang/jq#764 And the same solution works here: |
Another alternative for vim users: |
The problem I have with the missing yaml highlighting is that I know that this has the technical reason that without the 'y' switch jq does the highlighting, but it's a strange behavior anyway. So I would vote for directly implementing it into the yq wrapper. |
Until Pygments improve it's YAML colourisation (relates to #67), an all-Python highlight seems to be out of question. The cli-highlight mentioned above is in TypeScript/npm which probably pull the world... A lot of binary highlighter exists; my personal favourite is bat, properly packaged, supporting as of today 124 languages and support automatic pagination as requested in stedolan/jq#764. Older binary alternatives would be |
nice |
You don't need Pygments to highlight YAML since you already have an AST. You can customize the emitter, something like this: class ColoredDumper(yaml.SafeDumper):
def write_indicator(self, indicator: str, need_whitespace, **kw):
self.stream.write('\x1b[34m')
super().write_indicator(indicator, need_whitespace, **kw)
self.stream.write('\x1b[0m')
def process_scalar(self):
if self.simple_key_context:
self.stream.write('\x1b[31m')
elif self.event.tag == 'tag:yaml.org,2002:int':
self.stream.write('\x1b[32m')
elif self.event.tag == 'tag:yaml.org,2002:str':
...
super().process_scalar()
self.stream.write('\x1b[0m') |
I for one am using yq . resume.yaml -y | bat -ppl YAML And boy, it looks good! I should make a shell function that pipes the output like that. Edit: here's the shell function function yqq {
yq -y $1 $2 | bat -ppl YAML
} |
Awesome project! I'm dealing now with a lot of yml files to be processed in kubernetes...
Is there a way to parse and print the key values in color?
Maybe just the same colors as
jq
or like in the vim editor?The text was updated successfully, but these errors were encountered: