mgeisler / textwrap

An efficient and powerful Rust library for word wrapping text.
MIT License
446 stars 44 forks source link

consider treating ANSI/CSI/OSC sequences as zero width #511

Open samliddicott opened 1 year ago

samliddicott commented 1 year ago

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.

mgeisler commented 1 year ago

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?