Skip to content
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

Feature textwrapping #60

Merged
merged 6 commits into from
Mar 10, 2016
Merged

Feature textwrapping #60

merged 6 commits into from
Mar 10, 2016

Conversation

jrmiller82
Copy link
Contributor

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.

}
defer ui.Close()

p := ui.NewPar("Press q to QUIT THE DEMO. [There](fg-blue) are other things [that](fg-red) are going to fit in here I think. What do you think? Now is the time for all good [men to](bg-blue) come to the aid of their country. [This is going to be one really really really long line](fg-green) that is going to go together and stuffs and things. Let's see how this thing renders out.\n Here is a new paragraph and stuffs and things. There should be a tab indent at the beginning of the paragraph. Let's see if that worked as well.")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try using Go's [multiline string syntax] here, it will help readability.

`First line
Second line
Third line`

@gizak gizak merged commit 7dd60de into gizak:master Mar 10, 2016
@gizak
Copy link
Owner

gizak commented Mar 10, 2016

👍 Merged but with some modification: BuildWrap will break compatibility so I convert it to wrapTx as a normal function call.

@jrmiller82
Copy link
Contributor Author

Wonderful. Glad you found it useful.

@jrmiller82 jrmiller82 deleted the feature-textwrapping branch March 11, 2016 21:23
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

Successfully merging this pull request may close these issues.

3 participants