-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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...) | ||
} |