Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Gizak:
Here's a quick and dirty addition of text wrapping to anything called with NewPar. If the Par has a Par.WrapLength greater than x, a new varation of Build called BuildWrap is called. It still retains your neat markdown color syntax while getting nice naive wrapping of the text.
It's less efficient than it could be; I'm self taught so my logic might not be the best. I used a loop that breaks and re-reruns a lot to make sure the unwrapped and wrapped texts were properly compared and to avoid index errors. There is likely a more efficient way to do this; but, since we're just talking about wrapping small amounts of text, and with Go's inherent speed, I'm not too worried about it.
It imports (but does not vendor) github.com/mitchellh/go-wordwrap (MIT licensed). The import is called in textbuilder.go. The src is fairly short if you want to bring it inside of termui so you're not having to import it. But, I'll leave that decision up to you.
I also added the BuildWrap func to the TextBuilder interface as it was the only way to get around not having to entirely rewrite the whole call stack. Maybe in the future it would be best to just rewrite Build to take into account the wrapping logic in BuildWrap; but, I couldn't exactly grok your build stuff...
Let me know what you think. Termui rocks!
Oh, after the PR, the import statement in the example file points to my fork, and not the main repo; it will need to be changed.