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

Added option to render styles with optional separator #249

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion style.go
Expand Up @@ -110,6 +110,12 @@ func joinString(strs ...string) string {
return strings.Join(strs, " ")
}

// joinString joins a list of strings into a single string separated with a
// space.
func joinStringWithSeparator(separator string, strs ...string) string {
return strings.Join(strs, separator)
}

// SetString sets the underlying string value for this style. To render once
// the underlying string is set, use the Style.String. This method is
// a convenience for cases when having a stringer implementation is handy, such
Expand Down Expand Up @@ -177,6 +183,11 @@ func (s Style) Inherit(i Style) Style {

// Render applies the defined style formatting to a given string.
func (s Style) Render(strs ...string) string {
return s.RenderWithSeparator(" ", strs...)
}

// Render applies the defined style formatting to a given string.
func (s Style) RenderWithSeparator(separator string, strs ...string) string {
if s.r == nil {
s.r = renderer
}
Expand All @@ -185,7 +196,7 @@ func (s Style) Render(strs ...string) string {
}

var (
str = joinString(strs...)
str = joinStringWithSeparator(separator, strs...)

p = s.r.ColorProfile()
te = p.String()
Expand Down