markus-wa / cq

Clojure Query: A Command-line Data Processor for JSON, YAML, EDN, XML and more

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pretty indendation and coloring should be separate options

hukka opened this issue · comments

Currently the only options are to either indent and colorize, or not do either. Colors make it difficult to work with files, or really anything that cannot handle the terminal/ANSI color codes. Would be nice to have command line options to have the pretty indentation without colors.

Or perhaps logic that can see if stdout is attached to a TTY, but looks like that can get pretty hairy in JVM. I guess even more so with graalvm.

So maybe don't force puget/cprint here but use ppt/pprint or puget/pprint? https://github.com/markus-wa/cq/blob/main/src/cq/formats.clj#L42

Since this repo is in Hacktoberfest I could be interested in doing a PR on this.

Thanks for the suggestion!

I think let's start with --color=off --color=auto (default) --color=on

with shorthands -c for on and -C for off

off = puget/pprint
on = puget/cprint
auto = on (later we can add tty detection)

happy for a PR on this @Macroz

pretty was released with automatic logic for enabling colors. Seems pretty straightforward: clj-commons/pretty@7cb0c16

Thanks @hukka - I've created #18 to support this.

PRs welcome as I probably won't get to this for a while

So I implemented #18 as described, but I'm not sure this logic (from pretty) works as desired.

The code detects if you are in a TTY alright, but if you don't pipe to a file but to your terminal (e.g., for one-off manual use and exploration), you probably want to see the colors. You are likely also not in a REPL. So this kind of detection would mean the default is uncolored, and you must force the colors with a flag pretty much always.

Any more ideas?

Thanks @Macroz - I think that's as good as it gets.

As far as I'm aware there is no way to differentiate between pipe to command vs pipe to file (also, commands like tee may write to both a file and to TTY).

It's preferrable to break colouring vs breaking pipe to file.

Would you be able to open a PR? 😄

Right!

How about this for a PR #20?