Skip to content

Commit

Permalink
Add color package that I had creeping around in my GOPATH
Browse files Browse the repository at this point in the history
Fixes #1
  • Loading branch information
Joel Jensen committed Oct 3, 2017
1 parent 262cfbb commit ce0d340
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
53 changes: 53 additions & 0 deletions color/color.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Package color is a very basic ANSI escape sequence colorer.
// Use it like this:
//
// fmt.Println(color.Text(color.Red) + "I AM SO RED" + color.Reset())
// fmt.Println(color.All(color.Red, false, color.White) + "Red on white." + color.Reset())
//
package color

import (
"strconv"
)

type Color int

const (
Black Color = iota + 1
Red
Green
Yellow
Blue
Magenta
Cyan
White
)

func Text(c Color) string {
return "\x1b[" + strconv.Itoa(int(c)+29) + "m"
}
func All(foreground Color, bright bool, background Color) string {
if bright {
return "\x1b[1;" + strconv.Itoa(int(foreground)+29) + ";" + strconv.Itoa(int(background)+39) + "m"
} else {
return "\x1b[" + strconv.Itoa(int(foreground)+29) + ";" + strconv.Itoa(int(background)+39) + "m"
}
}
func Reset() string {
return "\x1b[m"
}

// Error() returns an error string colored red
func Error(e error) string {
return Text(Red) + e.Error() + Reset()
}

// Pass() returns a cute little green check mark ✓
func Pass() string {
return Text(Green) + "✓" + Reset()
}

// Fail() returns a cute little red cross mark ✗
func Fail() string {
return Text(Red) + "✗" + Reset()
}
3 changes: 1 addition & 2 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
"os"
"unsafe"

"color"

"github.com/yobert/alsa/color"
"github.com/yobert/alsa/misc"
"github.com/yobert/alsa/pcm"
)
Expand Down

0 comments on commit ce0d340

Please sign in to comment.