Skip to content

Commit

Permalink
Make coloring function public
Browse files Browse the repository at this point in the history
  • Loading branch information
mkchoi212 committed Jun 1, 2018
1 parent 729cceb commit 16b474b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions color/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
)

// Defines the color of the text
const (
FgBlack = iota
FgRed
Expand All @@ -13,14 +14,17 @@ const (
FgPurple
)

// Defines the style of the text
const (
Regular = iota + 1
Light
Highlight
Underline
)

func colorString(color int, style int, format string, a ...interface{}) string {
// Apply applies a `color` and a `style` to the provided `format`
// It does this by using ANSI color codes
func Apply(color int, style int, format string, a ...interface{}) string {
var str string
if len(a) == 0 {
str = format
Expand All @@ -32,25 +36,25 @@ func colorString(color int, style int, format string, a ...interface{}) string {

// Red returns a string with red foreground
func Red(style int, format string, a ...interface{}) string {
return colorString(FgRed, style, format, a...)
return Apply(FgRed, style, format, a...)
}

// Yellow returns a string with red foreground
func Yellow(style int, format string, a ...interface{}) string {
return colorString(FgYellow, style, format, a...)
return Apply(FgYellow, style, format, a...)
}

// Green returns a string with green foreground
func Green(style int, format string, a ...interface{}) string {
return colorString(FgGreen, style, format, a...)
return Apply(FgGreen, style, format, a...)
}

// Blue returns a string with blue foreground
func Blue(style int, format string, a ...interface{}) string {
return colorString(FgBlue, style, format, a...)
return Apply(FgBlue, style, format, a...)
}

// Black returns a string with black foreground
func Black(style int, format string, a ...interface{}) string {
return colorString(FgBlack, style, format, a...)
return Apply(FgBlack, style, format, a...)
}

0 comments on commit 16b474b

Please sign in to comment.