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

Machine-readable (JSON) output #525

Open
akx opened this issue Mar 21, 2023 · 0 comments
Open

Machine-readable (JSON) output #525

akx opened this issue Mar 21, 2023 · 0 comments

Comments

@akx
Copy link
Contributor

akx commented Mar 21, 2023

I know this is a bit leftfield, maybe, but I have a project where I'd like to use Indicatif's TTY progress bars when human eyes are operating the application, but with an option to use JSON (NDJSON/jsonlines) output instead when working as a subprocess, and I'd like to do this without duplicating the ETA, etc. calculations and rate limiting since Indicatif is already doing a great job at that.

What would be a good approach for this?

Since ProgressStyle isn't a trait, it's not easy to pass in a JSON-formatting ProgressStyle from userland (or at least I couldn't figure it out); just passing in a JSON-esque template for a regular ProgressStyle isn't great since it doesn't do JSON encoding for strings – and even so, the TTY-related code (moving cursors and clearing progress bars and all that) wouldn't be necessary; you'd just always print a newline after a message.

To clarify, I'm envisioning something like ProgressBar::new_json(["pos", "len", "eta"]) outputting e.g.

{"pos": 1, "len": 100, "eta": 14.3}
{"pos": 39, "len": 100, "eta": 7.7}
{"pos": 100, "len": 100, "eta": 0}

(with maybe a complete marker afterwards? That's a detail anyway.)

If there's no great way to do this from userspace, would a PR implementing something like this be appreciated and/or approved? 😄

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

1 participant