-
Notifications
You must be signed in to change notification settings - Fork 7
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
bunt::format_args & bunt::format #18
Comments
Also, ergonomics are not really great, with the workaround mentioned above: let mut buf = bunt::termcolor::Buffer::ansi();
let err = |e: &dyn Debug|
error!("Error while converting `bunt` format string {:?}: {:?}", $fmt_str, e);
if let Err(e) = bunt::write!(buf, $fmt_str, $($arg),*) {
err(&e)
} else {
match std::str::from_utf6(buf.as_slice()) {
Err(e) => err(&e),
Ok(msg) => info!(msg),
};
} 😉 (Fortunately, this code only has to exist once) |
Hi there. Regarding Regarding
The proc macro code certainly does, but this happens at compile time. The emitted code does not allocate itself, only the called
Are you sure about this? Writing into a standard stream shouldn't allocate, no? |
Yes, I'm pretty sure (if I'm not missing anything). pub fn into_inner(self) -> Vec<u8>
Consume this buffer and return the underlying raw data.
On Windows, this unrecoverably drops all color information associated with the buffer. And the inner data for ANSI content is
I didn't study the code of
Alright, still thanks for the response! Unfortunately, I'm also busy with many different projects already... Btw., are you aware of owo_colors?
The next release will even have functionality that makes it easy to create style themes, which I believe is important (a default theme that's optimized for dark backgrounds is often not very readable on white backgrounds). |
Ah surel, if you need to write to
We could, but then all the color information is lost. The code
I didn't know that lib. |
Hi,
Something that sometimes would be useful, is
bunt::format_args
(and maybebunt::format
).This would come in handy, for example, to format logging messages with
bunt
. In this case, a user can't currently usebunt
s macros without allocating. Another use-case would be to store formatted strings (probably only viabunt::format
with an allocation).The best option I could come up with is to
write!
to atermcolor::Buffer
, but this does allocate.(By the way, does
bunt
allocate internally?)My current use case is, that I have a
log
macro that accepts abunt
format string and arguments (which prints regular status messages for the user). I also have an option to activate debugging output, which activates tracing.So basically, there are two different log output formats (my own and
tracing
).It would be better if – if
debug
is activated – mylog
macro redirects messages totracing
. But, as mentioned above, this is only possible viatermcolor::Buffer
to which I writebunt
s output.How hard would it be to add a variant of std::format_args to
bunt
?The text was updated successfully, but these errors were encountered: