Skip to content

Commit ccc377a

Browse files
committed
feat: Add Colorize alias "With"
1 parent 0a05843 commit ccc377a

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ go get github.com/TwiN/go-color
2020

2121
### Function
2222

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

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

4242
I'm not usually a big fan of having two methods doing the same thing, but since
4343
this package doesn't have much room for growth (its only purpose is to colorize

color.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ func Ize(color, s string) string {
4848
return Colorize(color, s)
4949
}
5050

51+
// With is an alias for the Colorize function
52+
//
53+
// Example:
54+
//
55+
// println(color.With(color.Red, "This is red"))
56+
func With(color, s string) string {
57+
return Colorize(color, s)
58+
}
59+
5160
// Colorize wraps a given message in a given color.
5261
//
5362
// Example:

color_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ func TestColorize(t *testing.T) {
5252
if output != scenario.ExpectedOutput {
5353
t.Errorf("expected %s, got %s", scenario.ExpectedOutput, output)
5454
}
55+
// Ize is an alias of Colorize, therefore the result should be the same
56+
usingIze := Ize(scenario.Color, "test")
57+
if usingIze != scenario.ExpectedOutput {
58+
t.Errorf("expected %s, got %s", scenario.ExpectedOutput, usingIze)
59+
}
60+
// With is an alias of Colorize, therefore the result should be the same
61+
usingWith := With(scenario.Color, "test")
62+
if usingWith != scenario.ExpectedOutput {
63+
t.Errorf("expected %s, got %s", scenario.ExpectedOutput, usingWith)
64+
}
5565
})
5666
}
5767
}

0 commit comments

Comments
 (0)