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

Suggestion: Automatic pretty printing if stdout is a tty #169

Closed
nagy opened this issue Feb 8, 2022 · 4 comments
Closed

Suggestion: Automatic pretty printing if stdout is a tty #169

nagy opened this issue Feb 8, 2022 · 4 comments

Comments

@nagy
Copy link

nagy commented Feb 8, 2022

Hello, interesting project, thank you.

Would it make sense to check whether stdout is connected to a terminal via isatty(3) and then automatically enable pretty printing? I could imagine that, when you are typing on the terminal, you would want to see an easier to read json output, but when you are piping to other programs the size should be small.

You can test how the output behaves when it is not a tty by piping into cat like so:

$ jo a=2 | cat
@gromgit
Copy link
Collaborator

gromgit commented Feb 9, 2022

I dunno. From my POV, jo is meant to [a] be simple, and [b] generate machine-readable output by default, while making concessions to human readability on the rare occasion it's needed.

It's also mildly annoying to do the following dance:

$ jo <something_that_generates_copious_output>
# ARGH! A thousand lines of pretty-printed text!
$ jo <something_that_generates_copious_output> | less
# ARGH! Everything's squished together!
$ jo -p <something_that_generates_copious_output> | less

So yeah, I'd much rather have jo not guess what kind of output I want.

@jpmens
Copy link
Owner

jpmens commented Feb 9, 2022

I agree with @gromgit. At best we could introduce an environment variable (JO_PRETTY) which, when set to 1 or true or something, would automate pretty-printing, but that's likely also overkill as you can easily do this with a small script.

@Sashank999
Copy link

I think we can add -pretty command line option rather than environment variables. It is a long option so it won't be mistaken, instead of something like -p.

@jpmens
Copy link
Owner

jpmens commented Apr 9, 2022

-p already exists; there is no need to make a long option of it.

@jpmens jpmens closed this as completed Apr 9, 2022
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

4 participants