Skip to content
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

Complex formatting settings are ignored #59

Open
QazerLab opened this issue Oct 31, 2019 · 3 comments
Open

Complex formatting settings are ignored #59

QazerLab opened this issue Oct 31, 2019 · 3 comments

Comments

@QazerLab
Copy link

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

@joshtriplett
Copy link
Collaborator

That does indeed look like a bug to me, albeit a difficult one to fix.

@d-e-s-o
Copy link

d-e-s-o commented Jan 18, 2020

I am hitting the same problem :-(

@zzau13
Copy link

zzau13 commented Apr 1, 2020

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

d-e-s-o added a commit to d-e-s-o/apcacli that referenced this issue May 16, 2020
Colors can help a lot in decreasing the time it takes to understand a
listing or at least infer where to look at more closely. To that end,
this change enables the coloring of gains/losses when printing
positions.
There are various crates that allow us to colorize text in a terminal
using ANSI escape sequences, all with different trade-offs. We currently
rely on the yansi crate for doing this job. The downside is that it is a
new dependency.
Ideally we would want to use ansi_term instead (which is already pulled
in by other dependencies), but it turns out that the color enabled
strings it produces do not handle advanced formatting options as we use
them properly. See ogham/rust-ansi-term#59 for
details.
We also have used the colored crate successfully, but it does not
support RGB colors (only predefined ones) and the default green is
commonly too bright. Also, it comes with more dependencies than
seemingly necessary.
d-e-s-o added a commit to d-e-s-o/apcacli that referenced this issue Jun 21, 2020
Colors can help a lot in decreasing the time it takes to understand a
listing or at least infer where to look at more closely. To that end,
this change enables the coloring of gains/losses when printing
positions.
There are various crates that allow us to colorize text in a terminal
using ANSI escape sequences, all with different trade-offs. We currently
rely on the yansi crate for doing this job. The downside is that it is a
new dependency.
Ideally we would want to use ansi_term instead (which is already pulled
in by other dependencies), but it turns out that the color enabled
strings it produces do not handle advanced formatting options as we use
them properly. See ogham/rust-ansi-term#59 for
details.
We also have used the colored crate successfully, but it does not
support RGB colors (only predefined ones) and the default green is
commonly too bright. Also, it comes with more dependencies than
seemingly necessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants