Skip to content

Commit

Permalink
Seperate color as seperate package
Browse files Browse the repository at this point in the history
  • Loading branch information
mkchoi212 committed Jan 1, 2018
1 parent 6ffb5b1 commit 2cbb1cd
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions color/color.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package color

import (
"fmt"
)

const (
FgBlack = 0
FgRed = 1
FgGreen = 2
FgYellow = 3
FgBlue = 4
FgPurple = 5
)

const (
Regular = 1
Light = 2
Highlight = 3
Underline = 4
)

func colorString(color int, style int, format string, a ...interface{}) string {
var str string
if len(a) == 0 {
str = format
} else {
str = fmt.Sprintf(format, a...)
}
return fmt.Sprintf("\033[3%d;%dm%s\033[0m", color, style, str)
}

// Black is a convenient helper function to return a string with black foreground
func Black(style int, format string, a ...interface{}) string {
return colorString(FgBlack, style, format, a...)
}

// Red is a convenient helper function to return a string with red foreground
func Red(style int, format string, a ...interface{}) string {
return colorString(FgRed, style, format, a...)
}

// Green is a convenient helper function to return a string with green foreground
func Green(style int, format string, a ...interface{}) string {
return colorString(FgGreen, style, format, a...)
}

// Yellow is a convenient helper function to return a string with yellow foreground
func Yellow(style int, format string, a ...interface{}) string {
return colorString(FgYellow, style, format, a...)
}

// Blue is a convenient helper function to return a string with blue foreground
func Blue(style int, format string, a ...interface{}) string {
return colorString(FgBlue, style, format, a...)
}

// Purple is a convenient helper function to return a string with purple foreground
func Purple(style int, format string, a ...interface{}) string {
return colorString(FgPurple, style, format, a...)
}

0 comments on commit 2cbb1cd

Please sign in to comment.