Complex formatting settings are ignored
QazerLab opened this issue · comments
I'm trying to migrate my project from using colored to ansi_term
, as one of my dependencies already uses the latter. I was expecting this to be a straightforward replacement, but faced an issue: the Display
implementation in ansi_term
seems to ignore the formatting settings, e.g. with the following code
const DIGITS: &'static str = "1234567890";
fn main() {
let s = Color::Red.paint(DIGITS);
println!("{:.5}", s);
}
the expected behavior is: the provided format string is used; red string 12345
is printed;
the actual behavior is: the formatting settings are ignored; red string 1234567890
is printed.
Is this intentional, or a bug?
rustc
: 1.38.0
ansi_term
: 0.12.1
That does indeed look like a bug to me, albeit a difficult one to fix.
I am hitting the same problem :-(
I have forked this library because I needed it to depend on std::fmt::Dispay
.
But, can you solve the problem with:
Style::default().paint_fn(|f| write!(f, "{:.5}", 1.0))
I leave you the link to the coverage, repository and documentation