textwrap icon indicating copy to clipboard operation
textwrap copied to clipboard

consider treating ANSI/CSI/OSC sequences as zero width

Open samliddicott opened this issue 2 years ago • 1 comments
trafficstars

When wrapping, consider skipping over escape sequences such as those used for color control.

This way colorized messages can be wrapped.

Maybe https://docs.rs/strip-ansi-escapes/latest/strip_ansi_escapes/ has suitable code to steal.

samliddicott avatar Jun 13 '23 07:06 samliddicott

Hi @samliddicott,

Thanks for looking at Textwrap and opening issues. What is your use-case for Textwrap?

When wrapping, consider skipping over escape sequences such as those used for color control.

This way colorized messages can be wrapped.

We already do this: the display_width function will unconditionally skip across such escape sequences. The function is used for all width computations in the library.

Did you run into a problem using the wrapping functions on colored terminal text?

mgeisler avatar Jun 18 '23 08:06 mgeisler