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
Add option for JSON escaping for placeholder values #527
Conversation
if self.json_strings { | ||
match style { | ||
Some(s) => cur.push_str(&json::stringify(format!( | ||
"{}", | ||
s.apply_to(padded) | ||
))), | ||
None => cur.push_str(&json::stringify(format!("{padded}"))), | ||
} | ||
} else { | ||
match style { | ||
Some(s) => cur | ||
.write_fmt(format_args!("{}", s.apply_to(padded))) | ||
.unwrap(), | ||
None => cur.write_fmt(format_args!("{padded}")).unwrap(), | ||
} | ||
} | ||
} | ||
None => { | ||
if self.json_strings { | ||
match style { | ||
Some(s) => cur.push_str(&json::stringify(format!( | ||
"{}", | ||
s.apply_to(&buf) | ||
))), | ||
None => cur.push_str(&json::stringify(buf.clone())), | ||
} | ||
} else { | ||
match style { | ||
Some(s) => { | ||
cur.write_fmt(format_args!("{}", s.apply_to(&buf))).unwrap() | ||
} | ||
None => cur.push_str(&buf), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I'm personally not 100% happy with the complexity here, so if someone has better ideas...)
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 |
@djc No worries! I think I considered that too, but there was something missing in |
Would definitely be open to extending the API available to |
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...