Skip to content
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

Colorize output #20

Open
Nemo157 opened this issue Sep 6, 2019 · 2 comments
Open

Colorize output #20

Nemo157 opened this issue Sep 6, 2019 · 2 comments

Comments

@Nemo157
Copy link
Member

Nemo157 commented Sep 6, 2019

The CLI should support colorizing the output data to make it easier to read, both diagnostic and annotated hex encoding.

This will probably have to be generated by the library, easiest might be to inject ANSI escape codes in the output strings, can probably be used in the website with something like https://www.npmjs.com/package/ansi-to-html (how to support Windows terminals? hopefully there's something that can parse ANSI escapes and generate the correct commands, or maybe there's a library that gives higher-level colorized strings via annotated spans that can be converted into different formats as needed).

An example of what jq does for colorizing JSON which the diagnostic colorization can probably be based on:

jq-colors

@Nemo157
Copy link
Member Author

Nemo157 commented Sep 16, 2019

Some thoughts about colorizing:

echo '
^[[1;31m55799^[[0m^[[2;37m_1^[[31m(^[[1;37m{_^[[0m
    ^[[1;34m"timestamp"^[[1;37m: ^[[31m1(^[[0m^[[35m1567774432^[[0m^[[2;37m_2^[[31m)^[[0m,
    ^[[1;34m"foo"^[[1;37m: {_^[[0m
        ^[[1;34m"keys"^[[1;37m: [^[[0m
            ^[[32m"bar"^[[0m,
            ^[[32m"baz"^[[0m,
            ^[[32m"addr"^[[0m,
        ^[[1;37m]^[[0m,
        ^[[1;34m"data"^[[1;37m: [_
            ^[[1;37m[^[[0m
                ^[[35m11^[[0m,
                ^[[35m-46^[[0m^[[2;37m_0^[[0m,
                ^[[1;31m260^[[0m^[[2;37m_1^[[0m^[[31m(^[[0m^[[33mh'"'"'efe4dce59616'"'"'^[[31m)^[[0m,
            ^[[1;37m]^[[0m,
            ^[[1;37m[^[[0m
                ^[[35m8^[[0m,
                ^[[35m-14^[[0m,
                ^[[1;31m260^[[0m^[[2;37m_1^[[0m^[[31m(^[[0m^[[33mh'"'"'1d3fe80b8681'"'"'^[[31m)^[[0m,
            ^[[1;37m]^[[0m,
        ^[[1;37m]^[[0m,
    ^[[1;37m}^[[0m,
^[[1;37m}^[[0m^[[31m)
'

color-cbor

Probably too many colors, should merge some.

Fading out the bitwidth markers is sorta good, probably "faint + parent color" would work better than "faint + white"?

@chrysn
Copy link
Contributor

chrysn commented Jun 14, 2023

I'd consider using an external component for that, that manages different outputs (HTML, LaTeX, ANSI) and color themes.

Sadly, I don't have a concrete recommendation which one to use -- in Python I'd go with pygments, but on Rust there appears to only be syntect, but I can neither tell how heavyweight that is, nor whether it'll process pre-annotated data. But maybe it's not even a bad thing to let that be done in a completely separate step, from the highlighter's own grammar: yes we do have all the additional information, but having a grammar in a syntax highlighter rather than cbor-diag could be beneficial in situations when cbor-diag won't even process things, eg. while text is being entered by a user.

The downside of letting that parser do everything is that coloring the associated CBOR hex dumps (suggestion in #133) would be harder in such a setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants