Skip to content

Support multiple break sequences - #8

Open
jessp01 wants to merge 2 commits into
mitchellh:masterfrom
jessp01:support-multiple-break-sequences
Open

jessp01 wants to merge 2 commits into
mitchellh:masterfrom
jessp01:support-multiple-break-sequences

Conversation

@jessp01

@jessp01 jessp01 commented Jun 10, 2025

Copy link
Copy Markdown

For regular text, injecting newlines when wrapping is the obvious (and only reasonable) choice. However, consider a situation where you're wrapping a shell (or make) command: in such a case, you'll want a \, followed by a newline.

This pull introduces the breakSeq argument for that reason.
Unfortunately, since Go does not support optional arguments or overloading, this breaks the existing API, but I think it's worth it.

The alternative would be to introduce an additional method, but, IMHO, this is less sensible, especially since fixing existing code wouldn't be hard or time-consuming.

jessp01 added 2 commits June 10, 2025 16:32
For regular text, injecting newlines when wrapping is the obvious (and
only sensible) choice. However, consider a situation where you're
wrapping a shell (or `make`) command: in such a case, you'll want a `
\`, following by a newline.

This pull introduces the `breakSeq` argument for that reason.
Unfortunately, since Go does not support optional arguments or
overloading, this breaks the existing API but I think it's worth it.

The alternative is to introduce an additional method but, IMHO, this
is less sensible, especially since fixing existing code wouldn't be hard
or time consuming..
@sloumdrone

Copy link
Copy Markdown

As an outside party that uses this module:

A way to do this without breaking the api is add a variable (breakSequence) internally. This defaults to \n. Then add a setter or two:

  • func SetBreakSequence(s string): updates the breakSequence variable to s
  • func SetBreakSequenceDefault(): returns breakSequence variable to \n

So the two functions and one variable get added and then when wrapping you use the value of breakSequence as the line ending in the code.

This means folks can still call the regular function for wrapping. If someone has a need for a specific wrap to behave differently, change the break sequence, then restore it afterward if need be.

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.

2 participants