cyucelen / marker

🖍️ Marker is the easiest way to match and mark strings for colorful terminal outputs!
MIT License
48 stars 13 forks source link

Variadic Mark function #13

Closed cyucelen closed 5 years ago

cyucelen commented 5 years ago

Create a variadic Mark function that can take an arbitrary number of Matchers and colorizes the matches.

dapryor commented 5 years ago

Are you wanting to replace the old Mark function with this new version? Edit: Are you wanting to expect a slice of strings in return?

cyucelen commented 5 years ago

Sorry for the lack of information about the task.

I am expecting a new variadic Mark function to take a string, a color and an arbitrary number of Matchers and return a colorized string that all Matchers applied to it.

dapryor commented 5 years ago

No worries.

I think what I submitted may not be exactly what you want, so I will come back to that after work.

cyucelen commented 5 years ago

Waiting for your commits. Thanks!

dapryor commented 5 years ago

@cyucelen If you have free time, would you review pull request #14 and let me know what changes you would want to see. I missed that you have a builder.go file, so I didn't add the new function to that file.

dapryor commented 5 years ago

I made this a separate function to avoid breaking any code. We can go in and restructure Mark into being MarkMany then make the original Mark a private function.

Currently it is setup like: marker.go

func MarkMany(str string, c *color.Color, matcherFuncs ...MatcherFunc) string

How to use:

str := MarkMany("Skydome is Skydome. Give yourself freedom.", myColor, MatchAll("Skydome"), MatchAll("yourself"))

image

builder.go

func (m *MarkBuilder) MarkMany(c *color.Color, matcherFuncs ...MatcherFunc) *MarkBuilder

How to use:

b := MarkBuilder{}
actualString := b.SetString("Skydome is a data company.").
        MarkMany(redFg, MatchAll("data"), MatchAll("company")).
        Build()

image