get length of stringt with color syntax #1559
Answered
by
willmcgugan
mathisloevenich
asked this question in
Q&A
-
Strings like:
do obviously have a length of more than the actual printed length. I have looked into the docs and feel like rich.text should be able to make the job. However I did not find explicit documentation for this use case. |
Beta Was this translation helpful? Give feedback.
Answered by
willmcgugan
Oct 11, 2021
Replies: 1 comment 1 reply
-
That's correct, you can use the Text class. >>> from rich.text import Text
>>> text = Text.from_markup("[red]alert[/red]")
>>> len(text)
5 |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
mathisloevenich
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's correct, you can use the Text class.