ratatui / ansi-to-tui

Convert ansi colored text to tui::text::Text
https://crates.io/crates/ansi-to-tui
MIT License
57 stars 21 forks source link

Fix infinite loop on unsupported escape sequences #19

Closed gandalf3 closed 1 year ago

gandalf3 commented 2 years ago

This change attempts to parse most common escape codes the way a terminal would, but it is not exhaustive. At the very least it guarantees the escape character will be consumed which should prevent an infinite loop even if some unexpected garbage could end up in the output text.

Fixes: https://github.com/uttarayan21/ansi-to-tui/issues/20


I chose to eat unsupported escape codes as I believe this to be the behavior most likely expected by consumers of this library, and there are potential security ramifications of emitting control characters where developers may not be expect them.

However, I do think there is an argument to be made for allowing unsupported escape sequences through for a downstream client to handle. This implementation should facilitate implementing that as an option at a later date.

xixixao commented 1 year ago

@uttarayan21 thanks for the repo, care to merge this PR? Thanks!

uttarayan21 commented 1 year ago

Sorry about that. I totally forgot about this pr. I'll make a small change and merge this.

Edit: I'm being dumb.

uttarayan21 commented 1 year ago

But I did make a commit that keeps changing the style even if the span content is empty.

uttarayan21 commented 1 year ago

Thank you for the pr