Skip to content

Commit

Permalink
feat: Add Colorize alias "With"
Browse files Browse the repository at this point in the history
  • Loading branch information
TwiN committed Nov 20, 2022
1 parent 0a05843 commit ccc377a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ go get github.com/TwiN/go-color

### Function

You can use the `color.Colorize(color, message)` or `color.Ize(color, message)` function
You can use the `color.Colorize(color, str)`, the `color.Ize(color, string)`, or the `color.With(color, str)` function
in conjunction with a variable like so:
```go
package main
Expand All @@ -36,8 +36,8 @@ func main() {
}
```

Because I felt reading `color.Ize()` to be more visually pleasant than `color.Colorize()`,
I included `Ize()` as an alias for `Colorize()`.
Because I felt reading `color.With()`/`color.Ize()` to be more visually pleasant than `color.Colorize()`,
I included `Ize()` and `With()` as an alias for `Colorize()`.

I'm not usually a big fan of having two methods doing the same thing, but since
this package doesn't have much room for growth (its only purpose is to colorize
Expand Down
9 changes: 9 additions & 0 deletions color.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ func Ize(color, s string) string {
return Colorize(color, s)
}

// With is an alias for the Colorize function
//
// Example:
//
// println(color.With(color.Red, "This is red"))
func With(color, s string) string {
return Colorize(color, s)
}

// Colorize wraps a given message in a given color.
//
// Example:
Expand Down
10 changes: 10 additions & 0 deletions color_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ func TestColorize(t *testing.T) {
if output != scenario.ExpectedOutput {
t.Errorf("expected %s, got %s", scenario.ExpectedOutput, output)
}
// Ize is an alias of Colorize, therefore the result should be the same
usingIze := Ize(scenario.Color, "test")
if usingIze != scenario.ExpectedOutput {
t.Errorf("expected %s, got %s", scenario.ExpectedOutput, usingIze)
}
// With is an alias of Colorize, therefore the result should be the same
usingWith := With(scenario.Color, "test")
if usingWith != scenario.ExpectedOutput {
t.Errorf("expected %s, got %s", scenario.ExpectedOutput, usingWith)
}
})
}
}
Expand Down

0 comments on commit ccc377a

Please sign in to comment.