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

Control characters scewing padding. #115

Closed
Dygear opened this issue Aug 4, 2022 · 3 comments
Closed

Control characters scewing padding. #115

Dygear opened this issue Aug 4, 2022 · 3 comments

Comments

@Dygear
Copy link

Dygear commented Aug 4, 2022

This might not be your problem at all. I'm almost sure that is actually mine, but if that's the case, it would be nice to include some documentation on how to fix this. When formatting a string to pad right println!("{:>33}", "name".red()) extra padding must be applied to account for the control characters in the stream. Is there a way to tell the println!, format! and write! family of macros to not take into account control characters when calculating string length for output?

I ask because I'm building an interface that may apply multiple colors (one background, one foreground) to an output line and I'd love the text that it's outputting aligned correctly. The application that I'm making will make heavy use of colors to convey messages and meaning to the viewer. It take information from the Formula 1 '22 game over a UDP socket displays a timing and scoring screen like that found on the pitwall. As such, I've called it Pitwall. Displaying information like flag status for that driver (In a yellow flag, getting a blue flag) would be displayed by changing the background color of their name on the output making it exceedingly obvious when something has happened. I will also make use of it extensively for the timing component where when a fastest sector time or lap time is set that time will "go purple."

@kurtlawrence
Copy link
Collaborator

It is something we could look into, but it is by no means a trivial implementation.

If you want to progress with your project, you could possibly manually handle the padding with two print calls, one which just prints whitespace.

@9999years
Copy link

You can use the strip-ansi-escapes crate to remove such escape characters, and then you can measure the length of the resulting string.

@Dygear
Copy link
Author

Dygear commented Dec 26, 2023

@9999years Seems like a fair way to handle it.

@Dygear Dygear closed this as completed Dec 26, 2023
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

3 participants