Apply an ANSI style to a string, preserving any existing styles. :param val: string to be styled :param style: style instance or style definition to apply. :return: the stylized string
(val: str, style: StyleType)
| 84 | |
| 85 | |
| 86 | def stylize(val: str, style: StyleType) -> str: |
| 87 | """Apply an ANSI style to a string, preserving any existing styles. |
| 88 | |
| 89 | :param val: string to be styled |
| 90 | :param style: style instance or style definition to apply. |
| 91 | :return: the stylized string |
| 92 | """ |
| 93 | # Convert to a Rich Text object to parse and preserve existing ANSI styles. |
| 94 | text = Text.from_ansi(val) |
| 95 | text.stylize(style) |
| 96 | return ru.rich_text_to_string(text) |
| 97 | |
| 98 | |
| 99 | def strip_style(val: str) -> str: |
no outgoing calls
searching dependent graphs…