Open VorpalBlade opened 9 months ago
I ran into something sort-of similar in env_logger
. The way I worked around it is controlling what i used write!
on vs what I called .fmt(f)
on, see https://github.com/rust-cli/env_logger/commit/303a9c0ed288c5c7c15b6a74e29bfc1467bf9eab
From that experience, I think the problem is that write!
doesn't handle any of the format specifiers itself and does not forward them on. I reproduced this with std
at https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=0409fd1ae8ddd4d6b6e98ec9903dce7e
So to get his to work, you'd need to do something similar to what I did in env_logger
, use write!
for the styling and .fmt(f)
on the text.
@epage Thank you, this does indeed work! Perhaps it should be documented in anstyle somewhere? It seems like a bit of a gotcha.
I'm not sure how to fit this in. This is a problem specifically when you are creating a wrapper type for Display
and is a problem independent of whether anstyle
is in use or not.
That is a fair point. I would assume it is somewhat common to abstract away and use traits though. The code ends up a lot nicer that way.
I would expect the following (rather silly minimal case) to align columns properly:
It prints:
This is unexpected. So it seems the anstream
println
is not properly aware of how wide colour codes are.