-
-
Notifications
You must be signed in to change notification settings - Fork 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
Add unconditional wrapping #30
Conversation
Thanks for this PR, @erikgeiser! I like it and it's indeed much needed, but I wonder if it wouldn't be nicer to make the unconditional wrapping an option in the existing wordwrap package. What do you think? |
I think there might be cases where no word-wrapping is desired but the output should still be within a limit. In this case it would be awkward to be able to configure However, having an option in Also, after using it a bit I think the |
Ok, I'm convinced, that sounds rather reasonable. Do you want to fix the Adding an option to the |
Yes, i'll fix it in this PR. But the name |
Maybe it should be the other way around and called |
I'm not sure if we are thinking about the same concept. In my opionion the default behavior should be this:
or in the case where the user broke the line:
When disabling this option it should look like this:
or in the case where the user broke the line:
|
I see how that could be useful, too. Especially for source code. But I wonder, for human-readable text I would prefer this output (with the option enabled):
|
I can see where you are coming from but why should wrapping affect spaces that were put there intentionally by the user? In my opinion, the option is about removing spaces that have become redundant by the wrapping and not for general cleaning. If users want the behavior that you just showed, they can still strip leading spaces out of their lines before passing it to I primarily implemented |
Thank you for this contribution, Erik! |
This PR adds unconditional wrapping where each line is ended as soon as the limit is reached. The code is tested and documented in
README.md
. The PR also closes #29.This also works great in conjunction with word-wrapping when word-wrapping is preferred but the limit is mandatory (e.g. terminal width):
The unconditional wrapper also allows for some configuration:
Also I noticed a common pattern when checking ANSI markers, so I added helpers to the
ansi
package. These can also be applied to the other algorithms in another PR.