Skip to content

Commit

Permalink
Add yellow color function for warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mkchoi212 committed May 27, 2018
1 parent 62373a1 commit ae7f29c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
15 changes: 10 additions & 5 deletions color/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ func colorString(color int, style int, format string, a ...interface{}) string {
return fmt.Sprintf("\033[3%d;%dm%s\033[0m", color, style, str)
}

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

// Red returns a string with red foreground
func Red(style int, format string, a ...interface{}) string {
return colorString(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...)
}

// Green returns a string with green foreground
func Green(style int, format string, a ...interface{}) string {
return colorString(FgGreen, style, format, a...)
Expand All @@ -49,3 +49,8 @@ func Green(style int, format string, a ...interface{}) string {
func Blue(style int, format string, a ...interface{}) string {
return colorString(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...)
}
12 changes: 6 additions & 6 deletions color/color_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package color
import (
"os"
"testing"

"github.com/mkchoi212/fac/testhelper"
)

// Setup tests
Expand All @@ -15,15 +17,15 @@ var tests = []struct {
{Red, []string{"%s %s", "foobar", "hey"}, "\033[31;1mfoobar hey"},
{Green, []string{"%s", ""}, "\033[32;1m"},
{Blue, []string{"foobar"}, "\033[34;1mfoobar"},
{Yellow, []string{"foobar"}, "\033[33;1mfoobar"},
}

func TestColors(t *testing.T) {
// Redirect stdout
oldStdout := os.Stdout
_, w, err := os.Pipe()
if err != nil {
t.Fatalf("ColorString failed to redirect stdout because %s", err.Error())
}
testhelper.Ok(t, err)

os.Stdout = w

// Restore old stdout
Expand All @@ -47,8 +49,6 @@ func TestColors(t *testing.T) {
out = test.color(Regular, test.input[0], s...)
}

if test.expected != out {
t.Errorf("Color failed: got %s, want %s", out, test.expected)
}
testhelper.Equals(t, test.expected, out)
}
}

0 comments on commit ae7f29c

Please sign in to comment.