8000 Wrapping long lines · Issue #41 · webdiscus/ansis · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Wrapping long lines #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Radiergummi opened this issue Jun 8, 2025 · 1 comment
Closed

Wrapping long lines #41

Radiergummi opened this issue Jun 8, 2025 · 1 comment
Milestone

Comments

@Radiergummi
Copy link

Feature request

What is motivation or use case for adding/changing the behavior?

Breaking long lines with escape sequences in them, for example when wrapping text to fit inside table columns with a maximum width, causes rendering havoc.

The issue can be best understood like this:

<red>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod</red> tempor <green>invidunt ut labore</green> et dolore magna aliquyam erat, sed <blue>diam</blue> voluptua.

When wrapped, ignoring control characters, the snippet would look like so:

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed|
diam nonumy eirmod tempor invidunt ut labore et dolore magna| <-- 60 chars
aliquyam erat, sed diam voluptua.                           |

And when split naively, this would lead to the individual parts containing unclosed escape sequences:

<red>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed
diam nonumy eirmod</red> tempor <green>invidunt ut labore</green> et dolore magna
aliquyam erat, sed <blue>diam</blue> voluptua.

Finally, if you embed this in e.g. a table, you'll see styles "bleeding" into neighbour columns:

| Index | Synopsis                                                                          | Year |
|-------|-----------------------------------------------------------------------------------|------|
|    #1 | <red>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed                 | 2015 |
|       | diam nonumy eirmod</red> tempor <green>invidunt ut labore</green> et dolore magna |      |
|       | aliquyam erat, sed <blue>diam</blue> voluptua.                                    |      |

Describe the solution you'd like

It would be great if ansis included a utility similar to chalk/wrap-ansi that allows to safely split a formatted string while preserving its formatting.

Describe alternatives you've considered

Obviously one could just use chalk/wrap-ansi directly, but that's yet another library to include. Also, I feel like safe splitting should be part of ansis itself.

@webdiscus webdiscus added this to the analysis milestone Jun 10, 2025
@webdiscus
Copy link
Owner

Hallo @Radiergummi,

Thank you for the suggestion. However, I don't plan to include wrap-ansi functionality in Ansis. Ansis is purpose-built for ANSI coloring, nothing else.

Many maintainers care about package size and replaces big packages with smaller single-purpose alternatives.
A small size is one of Ansis's core strengths, the library is already as compact as Picocolors or even smaller. Adding the line-wrapping feature would enlarge the package size noticeably, that would erode that advantage.

Moreover, the npm ecosystem is built on the principle of composability: small, focused libraries that can be combined as needed.

wrap-ansi is a great library that works well alongside Ansis.

So while I appreciate the idea, keeping Ansis a small library remains a primary goal.

535E
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0