-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add color package that I had creeping around in my GOPATH
Fixes #1
- Loading branch information
Joel Jensen
committed
Oct 3, 2017
1 parent
262cfbb
commit ce0d340
Showing
2 changed files
with
54 additions
and
2 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,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() | ||
} |
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