Closed akx closed 1 year ago
Sorry for being slow to respond -- while I think your use case is something we'd like to accomodate, I think this PR is probably not the right way to go.
In thinking some more about it, do you think it would be feasible to write a custom ProgressTracker
that outputs the JSON? It seems like a viable path to me, in that the impl
could take care of all the particular JSON needs.
@djc No worries! I think I considered that too, but there was something missing in indicatif
that was required for that to work. I'll revisit that idea when I have the time :)
Would definitely be open to extending the API available to ProgressTracker
if that helps your use case, let me know.
Going to close this for now, feel free to reopen if you want to work on this again (or open a new one).
Refs #525 (I went ahead and wrote some code...).
This PR
json_strings
) to haveProgressStyle
escape all of the dynamic strings it outputs as JSON stringswith_json_keys
to create aProgressStyle
with a template that outputs a well-formed JSON objectIOW, a
ProgressStyle
withjson_strings(true)
and a template(this is what
ProgressStyle::with_json_keys(&["pos", "len", "prefix", "msg"])
would internally generate) will result in progress lines likewhich can then be sent to a
TermLike
target (#354, #526) to implement #525 :)If you like, I can put this behind a
feature
gate to avoid thejson
dependency – but what shouldindicatif
do when trying to do JSON output when it's not compiled in? I'm pretty sure we wouldn't want it to just output non-escaped JSON...